Click here to Skip to main content
15,891,981 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
The joys of not working with a design doc... This is the same application I've been working on for a bit of time as a side project (no "due date") and I'm now getting a bit further into it and hitting a bit of a snag.
This is the basic functionality of the app: I need it to log into a mail server, see how many messages are there, get some data from those messages and update a database. I've managed to get all that working and now for the problem, I need this to run every so many minuets (I'm thinking 5?). I've tried using a timer and I keep getting cross thread errors on my background workers (used to update the form). I'd post the code, but I kinda deleted it and well don't really have it any more. However all that I need is for the following to be called ever 5 or so min
MIDL
cleanUpFiles();
bgwRetreive.RunWorkerAsync();

cleanUpFiles writes the status to a text box, and there are a bunch of writes using the progress updates in bgwRetreive. The only other thing I can think of right now is to have a loop running on a thread checking for a time stamp, and then running the code when it hits it? Though I'm not really sure how that will affect resources as I'd have to run it in an infinite loop waiting for a cancel of some sort?
Obviously this is the first time I've tried to do something like this, thus the problems.
Thanks in advance.
Posted

 
Share this answer
 
Comments
MacRaider4 6-Jun-11 14:11pm    
That's kinda working, though I'm getting some funky output, see message in solution 2
MacRaider4 8-Jun-11 6:49am    
Working now, thanks for the info... just needed a little more tweaking.
Yup a timer should be good enough for this requirement. So go ahead and use one.
Post here if you face any further issues.
 
Share this answer
 
Comments
Manfred Rudolf Bihy 6-Jun-11 13:05pm    
Take 5!
Abhinav S 6-Jun-11 13:11pm    
Thank you Manfred.
MacRaider4 6-Jun-11 14:06pm    
Ok so after some tweaking and using some of the solution from John, I kinda have it working. Though I'm getting some funky output... if I run the code "normally" everything writes like it should... however when I use the timer I get results like:
48 15798
25 19893
1 23391

Where that should be a list of 1 - 65 (the current message count and the size), though the next part where it actually writes the text files, that is correct.
etc....
Writing letter #8
Writing letter #7
Writing letter #6
Writing letter #5
Writing letter #4
Writing letter #3
Writing letter #2
Writing letter #1

similar issue with my other output text
15 Subject: Hospital Daily Reports **Payment File**
12 Subject: Hospital (NEW Self-Pay Accounts) **New Business**
10 Subject: Print Statistics Report
9 Subject: Print Statistics Report
7 Subject: Hospital Daily Reports **Payment File**
6 Subject: Hospital Daily Reports **Payment File**
4 Subject: Print Statistics Report
2 Subject: Print Statistics Report
MacRaider4 8-Jun-11 6:48am    
Figured out my problem, was trying to save time (development wise) and wasn't storing the data in a variable first and then moving it to the text box like I normally do. It appears the one thread was running faster than the textbox update and thus the missing data in the text box. Moved all that to a string and life is good...

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