Click here to Skip to main content
15,907,874 members
Home / Discussions / C#
   

C#

 
AnswerRe: viewing and printing a pdf on different browser Pin
Bernhard Hiller17-Jul-13 21:43
Bernhard Hiller17-Jul-13 21:43 
GeneralRe: viewing and printing a pdf on different browser Pin
Amir Mohammad Nasrollahi29-Jul-13 6:40
professionalAmir Mohammad Nasrollahi29-Jul-13 6:40 
AnswerRe: viewing and printing a pdf on different browser Pin
Amir Mohammad Nasrollahi29-Jul-13 6:40
professionalAmir Mohammad Nasrollahi29-Jul-13 6:40 
QuestionProblem in creating Shortcut to desktop and uninstall program in user all program Pin
Sneha Bisht16-Jul-13 21:24
Sneha Bisht16-Jul-13 21:24 
AnswerRe: Problem in creating Shortcut to desktop and uninstall program in user all program Pin
Jay Nardev17-Jul-13 22:03
Jay Nardev17-Jul-13 22:03 
GeneralWindows Service: Timer vs Thread Pin
BBatts16-Jul-13 6:15
BBatts16-Jul-13 6:15 
GeneralRe: Windows Service: Timer vs Thread Pin
jschell16-Jul-13 8:18
jschell16-Jul-13 8:18 
GeneralRe: Windows Service: Timer vs Thread Pin
BBatts16-Jul-13 8:26
BBatts16-Jul-13 8:26 
GeneralRe: Windows Service: Timer vs Thread Pin
jschell17-Jul-13 8:40
jschell17-Jul-13 8:40 
GeneralRe: Windows Service: Timer vs Thread Pin
Richard MacCutchan16-Jul-13 20:30
mveRichard MacCutchan16-Jul-13 20:30 
GeneralRe: Windows Service: Timer vs Thread Pin
tasumisra17-Jul-13 0:27
tasumisra17-Jul-13 0:27 
GeneralRe: Windows Service: Timer vs Thread Pin
BBatts17-Jul-13 1:35
BBatts17-Jul-13 1:35 
GeneralRe: Windows Service: Timer vs Thread Pin
Nicholas Marty17-Jul-13 2:01
professionalNicholas Marty17-Jul-13 2:01 
I'd be using Timers for this purpose. As it's by far easier to control the execution of the timer instead of a thread.

I generally use the System.Threading.Timer with the following callback pattern:

Initialize it like that:
C#
// Declaration:
System.Threading.Timer _timer;

//Initialization:
_timer = new System.Threading.Timer(OnTimer, null, 10000, System.Threading.Timeout.Infinite);


And this callback method
C#
private void OnTimer(object state) {
   try {
      // Do your stuff here
   } catch (Exception ex) {
      // Errorhandling  
   } finally {
      // the first parameter is the delay until the callback method will be called again
      // the second parameter defines the interval in which it will be rais. Timeout.Infition -> Disabled
      _timer.Change(10000, System.Threading.Timeout.Infinite);
   }
}


To stop the timer just call:
C#
_timer.Change(System.Threading.Timeout.Infinite, System.Threading.Timeout.Infinite);


If you use it like that it should never ever be called concurrently as after the first event the timer is disabled until you manually reenable it (i.e. in the finally clause)

Greetings
GeneralRe: Windows Service: Timer vs Thread Pin
BBatts17-Jul-13 2:07
BBatts17-Jul-13 2:07 
QuestionHow to create Dynamic MainMenu formation in WinForm Application using DataBase Pin
hoabanxanh15-Jul-13 23:47
hoabanxanh15-Jul-13 23:47 
SuggestionRe: How to create Dynamic MainMenu formation in WinForm Application using DataBase Pin
Richard MacCutchan15-Jul-13 23:54
mveRichard MacCutchan15-Jul-13 23:54 
AnswerRe: How to create Dynamic MainMenu formation in WinForm Application using DataBase Pin
Pete O'Hanlon15-Jul-13 23:54
mvePete O'Hanlon15-Jul-13 23:54 
GeneralRe: How to create Dynamic MainMenu formation in WinForm Application using DataBase Pin
hoabanxanh25-Jul-13 0:52
hoabanxanh25-Jul-13 0:52 
QuestionICursor Pin
jojoba2015-Jul-13 22:10
jojoba2015-Jul-13 22:10 
AnswerRe: ICursor Pin
Pete O'Hanlon15-Jul-13 22:41
mvePete O'Hanlon15-Jul-13 22:41 
QuestionRe: ICursor Pin
jojoba2015-Jul-13 22:51
jojoba2015-Jul-13 22:51 
AnswerRe: ICursor Pin
Pete O'Hanlon15-Jul-13 23:05
mvePete O'Hanlon15-Jul-13 23:05 
QuestionRe: ICursor Pin
jojoba2016-Jul-13 17:22
jojoba2016-Jul-13 17:22 
AnswerRe: ICursor Pin
Pete O'Hanlon16-Jul-13 20:10
mvePete O'Hanlon16-Jul-13 20:10 
QuestionRe: ICursor Pin
jojoba2016-Jul-13 20:19
jojoba2016-Jul-13 20:19 

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.