Reputation: 19
I am taking care of the GUI thread of a piece of software. I have to display inside a GridView data that needs to be constantly polled from the underlying APIs. I created a method called Sync()
which updates the data, and I tried to make it thread safe by using BeginInvoke
and/or Invoke
. The Sync
method is called by a timer every five seconds or so.
The body of Sync
is never called, as for some reason it seems that my request is never pulled from the message pump. The code:
public void Sync()
{
if (this.InvokeRequired)
{
logger.Debug("Begin Invoke of Sync operation");
this.Invoke(new SyncDelegate(Sync));
logger.Debug("End Invoke of Sync operation");
}
else
{
logger.Debug("Inside body");
}
}
The log looks like:
10:00:00 Begin Invoke of Sync operation
... other stuff ...
10:00:05 Begin Invoke of Sync operation
... other stuff ...
10:00:10 Begin Invoke of Sync operation
The other messages are never printed.
The same for BeginInvoke
. "End Invoke ... " is printed but "inside body ..." is never printed.
I'm running on top of Unity3D and MonoDevelop (if this changes anything).
Upvotes: 0
Views: 152
Reputation: 19
Solved. Apparently I was creating the Windows Form outside of the Application.Run command. For some reason instantiating the Form inside the Application.Run comand did the trick
Upvotes: 0