|
-
Jun 13th, 2014, 10:41 AM
#1
Problem with SynchronizationContext.Current
I'm using the Pauser posted by jmc to manage my game time.
Within this code the SynchronizationContext.Current is put into a variable.
I'm wondering why I am getting different result for that SynchronizationContext.Current in circumstances which I believe to be the same.
The situation:
The GUI opens a Threadning.Threat in which the GameLoop is run, in this GameLoop the the pauser code is used which is putting the SynchronizationContext.Current into a variable. Since it is not the GUI thread SynchronizationContext.Current IMHO should return Nothing
The GameLoop is beeing used for direct simulation (it's working as expected there, SynchronizationContext.Current return Nothing) and for Replay(It is not working here, SynchronizationContext.Current returns context = {System.Windows.Forms.WindowsFormsSynchronizationContext}).
In both cases the GameLoo just calls another Sub in which either a SimulationStep or ReplayStep is done.
Where is my mistake?
You're welcome to rate this post!
If your problem is solved, please use the Mark thread as resolved button
Wait, I'm too old to hurry!
-
Jun 13th, 2014, 11:21 AM
#2
Re: Problem with SynchronizationContext.Current
 Originally Posted by opus
Since it is not the GUI thread SynchronizationContext.Current IMHO should return Nothing
Then your honest opinion is wrong. SynchronizationContext.Current will never be Nothing in a Windows Forms or WPF application. Every thread has a SynchronizationContext object associated with it.
-
Jun 13th, 2014, 11:23 AM
#3
Re: Problem with SynchronizationContext.Current
 Originally Posted by opus
the GameLoo
I gotta get me one of those
My usual boring signature: Nothing
 
-
Jun 13th, 2014, 01:12 PM
#4
Re: Problem with SynchronizationContext.Current
 Originally Posted by jmcilhinney
Then your honest opinion is wrong. SynchronizationContext.Current will never be Nothing in a Windows Forms or WPF application. Every thread has a SynchronizationContext object associated with it.
Maybe my explanation wasn't clear enough, my GameLoop is run on a seperate Thread NOT on the GUI thread.
My observations are:
When used on the GUI thread a SynchronizationContext is returned.
When used on a seperated "nomally" nothing is returned (except in the case posted above).
The code posted by jmcilhinney to handle that is working properly
info.context has been set by SynchronizationContext.Current
Code:
If info.context Is Nothing Then
'This is not a Windows GUI app so execute the method on the current thread.
Execute(info)
Else
'This is a Windows GUI app so execute the method on the original thread.
info.context.Post(AddressOf Execute, info)
End If
Is there a way to check in Debug-Mode wether I'm on the GUI-thread or not? In the moment I'm checking the Thread.Name, according to that it's not the GUI.
Although I'm getting SynchronizationContext, the .Post doesn't send the code to the Thread where the GameLoop is.
You're welcome to rate this post!
If your problem is solved, please use the Mark thread as resolved button
Wait, I'm too old to hurry!
-
Jun 13th, 2014, 01:26 PM
#5
Re: Problem with SynchronizationContext.Current
 Originally Posted by jmcilhinney
Then your honest opinion is wrong. SynchronizationContext.Current will never be Nothing in a Windows Forms or WPF application. Every thread has a SynchronizationContext object associated with it.
Hmmm... looks like I may have been wrong about that. I could have sworn that I'd tested that previously but perhaps not. Anyway, I'll have a closer look at this when I have time, which is not now I'm afraid.
-
Jun 13th, 2014, 01:36 PM
#6
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|