in Education by
What is the proper technique to have ThreadA signal ThreadB of some event, without having ThreadB sit blocked waiting for an event to happen? i have a background thread that will be filling a shared List. i'm trying to find a way to asynchronously signal the "main" thread that there is data available to be picked up. i considered setting an event with an EventWaitHandle object, but i can't have my main thread sitting at an Event.WaitOne(). i considered having a delegate callback, but a) i don't want the main thread doing work in the delegate: the thread needs to get back to work adding more stuff - i don't want it waiting while the delegate executes, and b) the delegate needs to be marshalled onto the main thread, but i'm not running a UI, i have no Control to .Invoke the delegate against. i considered have a delegate callback that simply starts a zero interval System.Windows.Forms.Timer (with thread access to the timer synchronized). This way the thread only needs to be stuck as it calls Timer.Enabled = true; but that seems like a hack. In the olden days my object would have created a hidden window and had the thread post messages to that hidden windows' HWND. i considered creating a hidden control, but i gather that you cannot .Invoke on a control with no handle created. Plus, i have no UI: my object could have been created on a web-server, service, or console, i don't want there to be a graphical control appearing - nor do i want to compile a dependency on System.Windows.Forms. i considered having my object expose an ISynchronizeInvoke interface, but then i would need to implement .Invoke(), and that's my problem. What is the proper technique to have thread A signal thread B of some event, without having thread B sit blocked waiting for an event to happen? JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
Here's a code sample for the System.ComponentModel.BackgroundWorker class. private static BackgroundWorker worker = new BackgroundWorker(); static void Main(string[] args) { worker.DoWork += worker_DoWork; worker.RunWorkerCompleted += worker_RunWorkerCompleted; worker.ProgressChanged += worker_ProgressChanged; worker.WorkerReportsProgress = true; Console.WriteLine("Starting application."); worker.RunWorkerAsync(); Console.ReadKey(); } static void worker_ProgressChanged(object sender, ProgressChangedEventArgs e) { Console.WriteLine("Progress."); } static void worker_DoWork(object sender, DoWorkEventArgs e) { Console.WriteLine("Starting doing some work now."); for (int i = 0; i < 5; i++) { Thread.Sleep(1000); worker.ReportProgress(i); } } static void worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { Console.WriteLine("Done now."); }

Related questions

0 votes
    What is the proper technique to have ThreadA signal ThreadB of some event, without having ThreadB sit ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 20, 2022 in Education by JackTerrance
0 votes
    Consider a hypothetical method of an object that does stuff for you: public class DoesStuff { BackgroundWorker ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 17, 2022 in Education by JackTerrance
0 votes
    point Which option is not available in the page background group of the design tab? * O Watermark Header Page border Select the correct answer from above options...
asked Dec 19, 2021 in Education by JackTerrance
0 votes
    point Which option is not available in the page background group of the design tab? * O Watermark Header Page border Select the correct answer from above options...
asked Dec 18, 2021 in Education by JackTerrance
0 votes
    I need to put a control to the right of my MenuStrip. The MenuStrip fades in colour away from the ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 17, 2022 in Education by JackTerrance
0 votes
    I need to put a control to the right of my MenuStrip. The MenuStrip fades in colour away from the ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 17, 2022 in Education by JackTerrance
0 votes
    Before a block of data in main memory can be output to the database, all log records pertaining to ... Buffer Management topic in chapter Recovery System of Database Management...
asked Oct 10, 2021 in Education by JackTerrance
0 votes
    What are the data controls available in ASP.NET?...
asked Apr 6, 2021 in Education by JackTerrance
0 votes
    Which feature of java 8 enables us to create a work stealing thread pool using all available processors at ... Miscellaneous of Java Select the correct answer from above options...
asked Feb 23, 2022 in Education by JackTerrance
0 votes
    Which feature of java 8 enables us to create a work stealing thread pool using all available processors at ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Oct 24, 2021 in Education by JackTerrance
0 votes
    Which of this method can be used to make the main thread to be executed last among all the threads? ... portion Multithreading of Java Select the correct answer from above options...
asked Mar 1, 2022 in Education by JackTerrance
0 votes
    Could someone tell me how to get into Data Science from a non-technical background? Select the correct answer from above options...
asked Jan 6, 2022 in Education by JackTerrance
0 votes
    ____ is a hard disk interface that uses parallel signal to transfer data and information Select the correct answer from above options...
asked Dec 1, 2021 in Education by JackTerrance
0 votes
    The _______ is that part of main memory available for storage of copies of disk blocks. (a) Buffer ... , Database Interview Questions and Answers for Freshers and Experience...
asked Oct 11, 2021 in Education by JackTerrance
...