Click here to Skip to main content
15,904,153 members
Please Sign up or sign in to vote.
2.00/5 (2 votes)
See more:
I have an application that has these functions:-
If no data file exists, read the files in a folder and create a new data file.
Read the data file.
Display its contents.

It also has a folder watcher which if it detects a newly created file in the folder, raises an event.
This event reads this file and adds it's details to the data file.

But now the problem:
I then try to re-display its contents.
I get a cross thread problem. Obviously raising the event creates a new thread.
I tried using the Delegate method, but there are too many functions, and the code will (I think) get too confusing.

I thought that I could omit the display routine, and put a button on the form to re-display it, thinking that by pressing the button, I would be back in the original thread. Yes and no. Mostly yes, but an important class no longer initialised, so can I be back on the original thread?

I am using Visual Basic in VS2008

Thanks for any ideas.
Posted
Comments
Stuart Nathan 22-May-12 8:27am    
I think the answer is because I used a System.Timer instead of a Windows,Form.Timer

Doing some investigation

1 solution

This was the problem.
System.Timer creates a different thread.
 
Share this answer
 
Comments
Alan N 22-May-12 12:42pm    
Yes, it does by default, but if the SynchronizingObject property is set to a form reference then it will raise the Elapsed event on the form's thread.
Stuart Nathan 22-May-12 13:23pm    
Yes I also discovered this. However it was easier to change the declaration. Thanks anyway

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900