Interviewer And Interviewee Guide

Microsoft.NET Interview Question:

How to stop a thread?

Submitted by: Administrator
NET allows to call System.Windows.Forms.Control functions only from thread where control was created. To run them from other thread we need to use Control.Invoke (synchronous call) or Control.BeginInvoke (asynchronous call) functions. For task like showing database records we need Invoke. To implement this :Delegate type for calling form function, delegate instance and function called using this delegate Invoke call from worker thread. Next problem is to stop worker thread correctly. Steps to do this:Set event "Stop Thread" Wait for event "Thread is stopped" While waiting for event process messages using Application.DoEvents function. This prevents deadlock because worker thread makes Invoke calls which are processed in main thread. Thread function checks in every iteration whether Stop Thread event is set. If event is set, function makes clean-up operations, sets event "Thread is stopped" and returns.
Submitted by: Administrator

Read Online Microsoft.NET Job Interview Questions And Answers
Copyright 2007-2024 by Interview Questions Answers .ORG All Rights Reserved.
https://InterviewQuestionsAnswers.ORG.