Click here to Skip to main content
16,017,707 members
Home / Discussions / C#
   

C#

 
QuestionHow to safely Form.Invoke from another thread? [modified] Pin
michal.kreslik25-Jul-07 1:19
michal.kreslik25-Jul-07 1:19 
AnswerRe: How to safely Form.Invoke from another thread? Pin
michal.kreslik25-Jul-07 1:44
michal.kreslik25-Jul-07 1:44 
AnswerRe: How to safely Form.Invoke from another thread? Pin
Tormod Fjeldskaar25-Jul-07 1:50
Tormod Fjeldskaar25-Jul-07 1:50 
GeneralRe: How to safely Form.Invoke from another thread? Pin
michal.kreslik25-Jul-07 2:47
michal.kreslik25-Jul-07 2:47 
GeneralRe: How to safely Form.Invoke from another thread? Pin
Luc Pattyn25-Jul-07 7:29
sitebuilderLuc Pattyn25-Jul-07 7:29 
GeneralRe: How to safely Form.Invoke from another thread? Pin
michal.kreslik25-Jul-07 11:41
michal.kreslik25-Jul-07 11:41 
GeneralRe: How to safely Form.Invoke from another thread? Pin
Luc Pattyn25-Jul-07 12:15
sitebuilderLuc Pattyn25-Jul-07 12:15 
GeneralRe: How to safely Form.Invoke from another thread? Pin
michal.kreslik25-Jul-07 21:43
michal.kreslik25-Jul-07 21:43 
Hi, Luc,

thanks for your comment. I'm not disposing of the form myself. I'm just closing it. But the whole point is in not allowing the form to get disposed before all possible Invokes on it are done.

I can briefly outline what is going on in my app: a server application is calling my client app every 100 ms via COM and refreshes its state. Sometimes it happens that the server stops calling my client app and I need to detect that.

For that purpose I've written a simple timer class that's started together with the app. The core class of my app stores the timestamp of the last COM call and my timer class checks every 200 ms whether the difference between DateTime.Now() and last COM call timestamp is higher than maximum allowed. If it is, it Invokes a method on a form that's telling me the connection has been lost. If it's not, it Invokes a method on a form that's telling me the connection is OK.

Obviously, the timer runs on a separate thread from the form's thread. When I'm closing the form (which does not close the application itself), I need to make sure that the timer executes the last Invoke on the form and shuts itself off.

And there's the problem. In order to make sure that the timer executes the last Invoke on the form safely, I need to prevent the form from disposing of itself before that last Invoke is done. But if I'm preventing the form from disposing of itself by putting a lock anywhere between the moment when the form starts closing and the moment when it starts getting disposed of, I'm effectively blocking the window message queue, so the last Invoke (which is executed while the form waits on a lock) never returns.

Thanks much for any help.

Michal
GeneralRe: How to safely Form.Invoke from another thread? Pin
michal.kreslik25-Jul-07 23:13
michal.kreslik25-Jul-07 23:13 
QuestionGROUP BY RECORD IN GRIDVIEW & EXPORT TO EXCEL Pin
krishanpanda25-Jul-07 1:07
krishanpanda25-Jul-07 1:07 
QuestionNeed VSD for asp.net case study Pin
Banjo Ayorinde25-Jul-07 1:05
Banjo Ayorinde25-Jul-07 1:05 
AnswerRe: Need VSD for asp.net case study Pin
UglyxXXx25-Jul-07 23:25
UglyxXXx25-Jul-07 23:25 
QuestionDataGridView Pin
sangramkp25-Jul-07 0:48
sangramkp25-Jul-07 0:48 
AnswerRe: DataGridView Pin
Tormod Fjeldskaar25-Jul-07 1:00
Tormod Fjeldskaar25-Jul-07 1:00 
Questiondatagrid focus Pin
praveenkumar palla25-Jul-07 0:45
praveenkumar palla25-Jul-07 0:45 
AnswerRe: datagrid focus Pin
Nouman Bhatti25-Jul-07 2:46
Nouman Bhatti25-Jul-07 2:46 
QuestionHiding Form after loading another Pin
Banjo Ayorinde25-Jul-07 0:12
Banjo Ayorinde25-Jul-07 0:12 
AnswerRe: Hiding Form after loading another Pin
Eduard Keilholz25-Jul-07 0:21
Eduard Keilholz25-Jul-07 0:21 
AnswerRe: Hiding Form after loading another Pin
PhilDanger25-Jul-07 3:51
PhilDanger25-Jul-07 3:51 
QuestionHiding Form after loading another Pin
Banjo Ayorinde25-Jul-07 0:09
Banjo Ayorinde25-Jul-07 0:09 
QuestionCreating a web based report in win app Pin
Banjo Ayorinde25-Jul-07 0:02
Banjo Ayorinde25-Jul-07 0:02 
Questionhoe to pass parameter in crystal report dynamically? Pin
help as an alias25-Jul-07 0:00
help as an alias25-Jul-07 0:00 
AnswerRe: hoe to pass parameter in crystal report dynamically? Pin
Nouman Bhatti25-Jul-07 2:54
Nouman Bhatti25-Jul-07 2:54 
GeneralRe: hoe to pass parameter in crystal report dynamically? Pin
help as an alias25-Jul-07 3:00
help as an alias25-Jul-07 3:00 
Questionmouse event Pin
cyn824-Jul-07 23:56
cyn824-Jul-07 23:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.