void OnDependencyChange(object sender,SqlNotificationEventArgs e)
{
MessageBox.Show("changed");
}
I'm running a query in ViewModel, I get the result (Let's say 10). If I try to insert instantly to SQL a new row, I don't the MessageBox. However, If I stop debugging and re-run my application, It will show as If the value changed which it did. Isn't SQLDependency supposed to give you real time notifications?
I was expecting the MessageBox to show the minute I add a new row in my table.
Related
Here I try to recover some values into variables.
I send a message to a server which returns different values. These values are read in a thread. I catch all values returned by the server with an event.
I try to store it but I have a problem: when I use my debugger I can see all refresh of my event only at the end (at display time in a WindowsForm).
Example with code:
ModuleProtocole.SendMessage("VER"); // after this command I will receive the version
ModuleProtocole.SendMessage("NA1"); // after this command I will receive the name of hardware
public void MessageRec(object source, MesACK e)
{
ReceptionMessage = e.getinfos(); //My globale variable ReceptionMessage is refresh for every new value on port
}
if(ReceptionMessage[0] == "M") //When i debug line by line ReceptionMessage is always = "Monitor" but at the end of debug all variable like "Name" is completed by the good word
Version = ReceptionMessage;
else Name=ReceptionMessage;
So my question is: Why my event is refresh only one time in debug? In my code, it should be trigger 2 times but only the first one is show and apply to variables in debug console.
I colleague found the solution: in the subscribe function to the event, add Console.Writeline(ReceptionMessage); then you can see refresh of ReceptionMessage.
Event is complicated in debug mode, this is the best way for see the refresh !
public void MessageRec(object source, MesACK e)
{
ReceptionMessage = e.getinfos();
Console.Writline(ReceptionMessage);
}
I have a windows service that uploads data to a database and a MVC-app that utilises said service. The way it works today is something like this:
Upload(someStuff);
WriteLog("Uploaded someStuff");
ReadData(someTable);
WriteLog("Reading someTable-data");
Drop(oldValues);
WriteLog("Dropping old values");
private void Upload(var someStuff)
{
using(var conn = new connection(connectionstring))
{
//performQuery
}
}
private void WriteLog(string message)
{
using(var conn = etc..)
//Insert into log-table
}
private string ReadData(var table)
{
using etc..
//Query
}
///You get the gist.
The client can then see the current status of the upload through a query to the log-table.
I want to be able to perform a rollback if something fails. My first thought was to use a BeginTransaction() and then lastly a transaction.Commit(), but that would make my status-message behave bad. It would just go from "starting upload" and then fastforward to the last step where it would wait for a long time before "Done".
I want the user to be able to see if the process is stuck on some specific step, but I still want to be able to perform a full rollback if something unexpected happens.
How do I achieve this?
Edit:
I don't seem to have been clear in my question. If I do a separate connection for the logging, that would indeed work-ish. The problem is that the actual code will execute super-fast so the statusmessages would pass so fast that the user wouldn't even be able to see them before the final "committing"-message that would take 99% of the upload-time.
Design your table so that it has a (P)ending, (A)ctive (D)eleted flag - then to perform an update, new records are created called 'pending' Status P - your very final stage is to change the current Active to Deleted, and the Pending to Active (you could do that in a transaction). At your leisure, you can then delete the Status D (deleted) records at some time.
In the event of an error, the 'pending' record could become Deleted
I've been working on this for about 8 months. It's been an annoyance more than anything until recently when I moved from a DataSet / DataTables to lists. Now the problem is a lot more prevalent (I think because the lists appear to be a LOT more efficient).
This question has been asked a few times but none of them really hit on what truly is going on (nor are any of them answered). The odd thing is I can't isolate where in my code this is causing the exception as the debugger pulls up the program.cs which only has this code:
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MyApp());
}
The application exception is on the Application.Run... line.
I'm using the DataGridView as a back ground processing log display. I have numerous background processes in a service that communicate back up to a winform app. The form listens for these messages (event handler / signalr) and also remove messages (like a FIFO queue) to not exceed a maximum defined amount in a list then I process the message and sort them into a BindingList[]. Then in the datagrid if I click on an item, it will display the full message in a textbox. I have multiselect turned off and again, the datagridview is read only.
Oh also, the BindingList[] is bound / rebound to the datagrid from another control so I can select which list to display in the datagridview. This is not the issue as I've isloated the issue by forcing a single specific list in the code and still have the problem.
To get this to crash, I can click on datagrid numerous times and eventually it will crash. If I really want to crash it quickly, I click on the datagridview and scroll (keyboard arrow) down and up and I can crash it in a few seconds.
I found this article (click here) on StackOverflow that describes what is going on. And in one of the comments it refers to a Microsoft Bug Report(click here) which stats this is by design! However, most are talking about manipulating the cells which I am not doing. The top message is nearly identical to what is happening to me but the programmer is using an inherited DataGridView so his solution will not work for me.
This does have to do with adding and or deleting items from the BindingList. I can get it to crash if I have either of the going on while scrolling / selecting in the DataGridView. But that code is very simple:
private void DelRow( string szTableName)
{
try
{
int nProcQueue = qdList.Queue(szTableName);
MsgQueues[nProcQueue].RemoveAt(0);
this.BeginInvoke(new MethodInvoker(Refresh_dgvDetail));
}
catch (Exception ex)
{
LogEx(ex);
}
}
and
private void AddRow(LogObject oLogObject, string szTableName)
{
try
{
int nQueueNumber = qdList.Queue(szTableName); // helper object to return queue number based off the name of the list
MsgQueues[nQueueNumber].Add(oLogObject);
this.BeginInvoke(new MethodInvoker(Refresh_dgvDetail));
}
catch (Exception ex)
{
LogEx(ex);
}
}
This really seems like a c# bug... Why MS would have this as designed is beyond me...?
Anyone know how to stop this behavior?
Grek40, you're right; I was wrong. I did the MethodInvoker for just the add; not the delete. It had to be done for both. Basically anything method that touches the datagridview needs to have MethodInvoker. This is an example of what I did:
this.Invoke((MethodInvoker)delegate { MsgQueues[nCurrentQueue].RemoveAt(0); });
Problem went away.
Set the column on the side to ReadOnly = true;
I'm creating an OPC client, that reads data from the server. I need to show status of connection with server in real time on my form. Can this be done?
For example:
private void checkStatus()
{
testValue.Text = cl.GetConnectionState().ToString();
}
cl.GetConnectionState() - method that shows connection status.
Add a timer to call that function. Function itself is fine, and should update the status correctly.
Although, if you want to do it right, I will say put this code in StateChange event handler. That way, your code will not run this function forever, and instead wait for the state to change.
i am new to infragistics and to winGrids
I have SQL database with the following table
Costumers
[ID][Name]
In addition , i have UserControl which has winGrid and add\remove buttons.
When the UserControll becomes, active winGrid datasource is bounded to the table
winGrd.DataSource = Tables.Costumers;
When user wants to add\remove data from costumers table he clicks the relevant button.
The table is changed accordingly but the displayed data in the grid is not changed.
I used
winGrd.Refresh();
but it does no effect
what is the way to do this, Code examples are welcome
thanks
---Edited ----
Adding code:
private void BtnAdd_Click(object sender, System.EventArgs e)
{
//...
DB.DataProxy.AddCostumer(txtType.Text);
winGrd.Refresh();
//...
}
AddCostumer method eventually calls for the following method that updates the costumer table
public void AddCostumer(string type)
{
Costumers.InsertOnSubmit(new InsertOnSubmit{ Name = name});
}
If your DataTable is being updated, the UltraGrid should be showing those changes for you. What you could try is to call
ultraGrid1.Rows.Refresh(Infragistics.Win.UltraWinGrid.RefreshRow.ReloadData);
or
ultraGrid1.Rows.Refresh(Infragistics.Win.UltraWinGrid.RefreshRow.RefreshDisplay);
Not sure, but, as from MSDN documentation on InsertOnSubmit()
The added entity will not appear in query results from this table until after SubmitChanges has been called.
So, perhaps, if you want the result appear immediately in the Costomers entity and then in the WinGrid, you should call, in the code above the SubmitChanges()
public void AddCostumer(string name)
{
Costumers.InsertOnSubmit(new Costumers() { Name = name});
// Submit the change to the database.
try
{
db.SubmitChanges();
}
catch (Exception e)
{
// message to the user???
}
}
Once you executed the add/remove command, re-pull the data from database and redo the binding. Set the DataGridView.DataSource to null before all that, just in case; you wouldn't want to display wrong data if the connection or any other database-related process fails.
I think it's because you are setting a DataSource that doesn't implements IBindableList which UltraGrid uses for automatically update data it changes.
You could try refreshing it manually setting DataSource to null and resetting DataSource again when you need to show new info.