.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

How do I know if a backgorund worker thread is done?

Posted By:      Posted Date: September 10, 2010    Points: 0   Category :.NET Framework
OK, I have a windows process that needs to run parallel tasks (still using .Net 3.5) and I have the following question: How can I tell when they are all "done" so I can safely stop the process? My pseudocode is as follows: public void RunStuff() {     while (!ShouldCancel)     {         List<ItemToDo> items = GetListOfItemsToDo();         foreach (ItemToDo item in items)         {             DoTheItem(item);         }         Sleep(10 seconds);     } } void DoTheItem(ItemToDo item) {     BackgroundWorker bw = new BackgroundWorker();     bw.DoWork += DoWorkEventHandler(bw_DoWork);     bw.RunWorkerAsync(item);       } void bw_DoWork(object sender, DoWorkEventArgs e) {     ItemToDo item = e.Argument as ItemToDo;     RunThisLongProcessWithThisItem(item); } void RunThisLongProcessWithThisItem(ItemToDo item) {     // do stuff that takes a long time (sometimes .5 seconds, sometimes 5 minutes....) } public void Dispose() {     int bwCounter = [[CountOfCurrentB

View Complete Post

More Related Resource Links

Process 65:0:1 (0x1b28) Worker 0x3DCD00E8 appears to be non-yielding on Scheduler 5. Thread creation



I have a 6GB database, and i have set a backup job on daily basis. problem is this i am getting some errors in sql error log when the backup job starts. the error as bellow.


The error not occurs daily its recorded after 3 or 4 days.


2008-08-13 19:01:17.62 Server      Using 'dbghelp.dll' version '4.0.5'
2008-08-13 19:01:17.64 Server      ***Unable to get thread context - no pss
2008-08-13 19:01:17.64 Server      * *******************************************************************************
2008-08-13 19:01:17.64 Server      *
2008-08-13 19:01:17.64 Server      * BEGIN STACK DUMP:
2008-08-13 19:01:17.64 Server      *   08/13/08 19:01:17 spid 0
2008-08-13 19:01:17.64 Server      *
2008-08-13 19:01:17.64 Server      * Non-yielding Scheduler
2008-08-13 19:01:17.64 Server      *
2008-08-13 19:01:17.64 Server      * *******************************************************************************
2008-08-13 19:01:17.64 Server      Stack Signature for the dump is 0x0000003A
Process 65:0:1 (0x1b28) Worker 0x3DCD00E8 appears to be non-yielding on Scheduler 5. Thread creation time: 12863135631614. Approx Thread CPU Used: kernel 531 ms, user 93 ms. Process Utilization 0%. System Idle 98%. Interval: 70002 ms.

Unable to cast COM object error when calling COM from .NET C# worker thread


I'm having an issue calling a COM object function from .NET C# client program. The COM object is written in C++ unmanaged. The problem only appears when I'm calling from a worker thread, it works fine if I call it from the UI thread. This is the error:

Unable to cast COM object of type 'gvAgileFileReaderLib.gvAgileFileReaderClass' to interface type 'gvAgileFileReaderLib.IgvMpiRead'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{616B5C39-C7FB-4C8C-85D4-27559DD83304}' failed due to the following error: Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL)).

I have tried the following methods but all of them fails:

1) Create the COM object on UI thread, and call its function via its interface (IgvMpiRead) in the worker thread

2) Create the COM object on the worker thread & access its function from worker thread

3) Tried with worker thread set to STA & MTA

I need to use the COM function is a worker thread to prevent a long processing from holding up my UI, but it just doesn't work when I try to call the COM function inside the worker thread.

The weird thing is that doing the same from a unmanaged C++ client works fine (I can create the com object on UI, and then call its function from worker thread). Is this problem caused by inter

How to pause resume Background Worker Thread?


We are working on a VB.Net window based application and we are using Visual Studio 2010 Professional.

In our application during the execution process we have used Background Worker thread and user have the option of cancelling the execution only.

Now we came across a situation that if user wants to pause the execution process then how we can pause the background worker thread so that it can be resumed on resuming the execution by the user?



Premjeet Singh

Regards, Premjeet Singh

ASP.NET Architecture - ASP.NET Worker Process - HTTP Pipleline - Http Modules and Handlers

"ASP.NET is a powerful platform for building Web applications, that provides a tremendous amount of flexibility and power for building just about any kind of Web application. Most people are familiar only with the high level frameworks like WebForms and WebServices which sit at the very top level of the ASP.NET hierarchy. In this article I'll describe the lower level aspects of ASP.NET and explain how requests move from Web Server to the ASP.NET runtime and then through the ASP.NET Http Pipeline to process requests.

Thread Performance: Resource Contention Concurrency Profiling in Visual Studio 2010


Visual Studio 2010 includes new resource contention profiling features that help detect concurrency contention among threads. We walk through a profiling investigation to demonstrate how you can pinpoint and fix resource contention problems in your code.

Maxim Goldin

MSDN Magazine June 2010

Thread Diagnostics: Performance Tuning with The Concurrency Visualizer in Visual Studio 2010


Understanding performance bottlenecks in multithreaded apps used to require significant instrumentation and analysis by expert developers. The Concurrency Visualizer in Visual Studio 2010 significantly reduces the burden of parallel performance analysis.

Hazim Shafi

MSDN Magazine March 2010

CLR Inside Out: Thread Management In The CLR


Getting the performance you want in concurrent applications is not as straightforward as you might think. See how common threading issues can affect your application.

Erika Fuentes and Eric Eilebrecht

MSDN Magazine December 2008

Editor's Note: new Thread(ReadEditorsNote).Start(); yourAttention.WaitOne();


Introducing the issue, Howard Dierking points out that you can't simply parallelize your code blindly if you expect to truly reap the benefits that parallelism promises.

Howard Dierking

MSDN Magazine October 2008

Pooled Threads: Improve Scalability With New Thread Pool APIs


The new threadpool APIs in Windows Vista and in the upcoming Windows Server 2008 provide advances that even native Windows developers can benefit from.

Robert Saccone

MSDN Magazine October 2007

Concurrent Affairs: Build a Richer Thread Synchronization Lock


In my last column, I showed the various thread synchronization mechanisms employed by the Microsoft® . NET Framework (see Concurrent Affairs: Performance-Conscious Thread Synchronization). I then examined the performance characteristics of all these mechanisms and determined that the Interlocked methods performed the best because the calling thread never has to transition to kernel mode.

Jeffrey Richter

MSDN Magazine March 2006

Concurrent Affairs: Performance-Conscious Thread Synchronization


In my career, I have architected and implemented many thread synchronization techniques. This has provided me with a lot of experience that has shaped the way I now think about thread synchronization problems.

Jeffrey Richter

MSDN Magazine October 2005

Basic Instincts: Thread Synchronization


My last three Basic Instincts columns have examined techniques for using asynchronous delegates and creating secondary threads. Those columns demonstrated how to introduce multithreaded behavior into your applications.

Ted Pattison

MSDN Magazine September 2004

.NET Column: The CLR's Thread Pool


How does the thread pool work in the CLR?

Jeffrey Richter

MSDN Magazine June 2003

.NET Column: Safe Thread Synchronization


By far, the most common use of thread synchronization is to ensure mutually exclusive access to a shared resource by multiple threads. In the Win32® API, the CRITICAL_SECTION structure and associated functions offers the fastest and most efficient way to synchronize threads for mutually exclusive access when the threads are all running in a single process.

Jeffrey Richter

MSDN Magazine January 2003

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend