Click here to Skip to main content
15,902,715 members
Home / Discussions / C#
   

C#

 
QuestionCreate dll Pin
Trih8-Apr-09 23:55
Trih8-Apr-09 23:55 
AnswerRe: Create dll Pin
stancrm9-Apr-09 0:08
stancrm9-Apr-09 0:08 
AnswerRe: Create dll Pin
Giorgi Dalakishvili9-Apr-09 0:08
mentorGiorgi Dalakishvili9-Apr-09 0:08 
AnswerRe: Create dll Pin
dojohansen9-Apr-09 0:34
dojohansen9-Apr-09 0:34 
QuestionStop while loop Pin
yesu prakash8-Apr-09 23:54
yesu prakash8-Apr-09 23:54 
AnswerRe: Stop while loop Pin
stancrm9-Apr-09 0:07
stancrm9-Apr-09 0:07 
GeneralRe: Stop while loop Pin
yesu prakash9-Apr-09 0:24
yesu prakash9-Apr-09 0:24 
GeneralRe: Stop while loop Pin
dojohansen9-Apr-09 0:49
dojohansen9-Apr-09 0:49 
The easiest way to put it in a background thread is to make sure you have a method signature that take one parameter of type object and then use ThreadPool.QueueUserWorkItem(new WaitCallback(method)) - "method" simply being the name of the method you wish to call.
bool stop;
void method(object dummy)
{
  while (!stop)
  {
     ...
  }
}

However, be aware that the code in method should not use any references to any controls. By default, doing so will result in an exception. You can make this go away by setting Control.CheckForIllegalCrossThreadCalls to false, but it's not a good practice to do so, I think because the controls aren't designed to be thread-safe. Depending on what you're doing, you may or may not decide that you don't care and just use the controls from the background thread anyway. I've done it many times (in apps for my own use only, where I don't really care if this one day leads to some odd behavior of a button because two threads tried to update it's text property at once, resulting in something weird and maybe beautiful) and I haven't had any problems with it, but there is undoubtedly a good reason why Microsoft decided to disallow this by default.
AnswerRe: Stop while loop Pin
Dino Mulahusic9-Apr-09 0:11
professionalDino Mulahusic9-Apr-09 0:11 
AnswerRe: Stop while loop Pin
Rob Philpott9-Apr-09 0:16
Rob Philpott9-Apr-09 0:16 
GeneralRe: Stop while loop Pin
yesu prakash9-Apr-09 0:19
yesu prakash9-Apr-09 0:19 
GeneralRe: Stop while loop Pin
Rob Philpott9-Apr-09 0:26
Rob Philpott9-Apr-09 0:26 
GeneralRe: Stop while loop Pin
Deresen9-Apr-09 2:57
Deresen9-Apr-09 2:57 
GeneralRe: Stop while loop Pin
Rob Philpott9-Apr-09 3:10
Rob Philpott9-Apr-09 3:10 
GeneralRe: Stop while loop Pin
Deresen9-Apr-09 3:16
Deresen9-Apr-09 3:16 
Questionreading excel contents Pin
mist_psycho8-Apr-09 23:30
mist_psycho8-Apr-09 23:30 
AnswerRe: reading excel contents Pin
Rob Philpott9-Apr-09 0:54
Rob Philpott9-Apr-09 0:54 
QuestionGeneric method: Cast an object to a return type T Pin
Spunky Coder8-Apr-09 23:26
Spunky Coder8-Apr-09 23:26 
AnswerRe: Generic method: Cast an object to a return type T Pin
0x3c08-Apr-09 23:37
0x3c08-Apr-09 23:37 
GeneralRe: Generic method: Cast an object to a return type T Pin
_groo_8-Apr-09 23:49
_groo_8-Apr-09 23:49 
GeneralRe: Generic method: Cast an object to a return type T Pin
Spunky Coder8-Apr-09 23:51
Spunky Coder8-Apr-09 23:51 
GeneralRe: Generic method: Cast an object to a return type T Pin
_groo_9-Apr-09 0:01
_groo_9-Apr-09 0:01 
GeneralRe: Generic method: Cast an object to a return type T Pin
Spunky Coder9-Apr-09 0:14
Spunky Coder9-Apr-09 0:14 
AnswerRe: Generic method: Cast an object to a return type T Pin
Rob Philpott8-Apr-09 23:42
Rob Philpott8-Apr-09 23:42 
GeneralRe: Generic method: Cast an object to a return type T Pin
Spunky Coder9-Apr-09 0:01
Spunky Coder9-Apr-09 0:01 

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.