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


Top 5 Contributors of the Month
Sharon Maxwell
Post New Web Links

How to pause resume Background Worker Thread?

Posted By:      Posted Date: April 10, 2011    Points: 0   Category :JQuery
 

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?

 

Regards,

Premjeet Singh


Regards, Premjeet Singh


View Complete Post


More Related Resource Links

Open dialogue box in background worker

  
Hi, I am getting an error trying to open a dialogue box in background worker. Please help.   Imports System Imports System.Drawing Imports System.Windows.Forms Imports System.IO Public Class Form1 Inherits Form Private folderBrowserDialog1 As FolderBrowserDialog Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click bgw.RunWorkerAsync() End Sub Private Sub BGW_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles bgw.DoWork Dim result As DialogResult = folderBrowserDialog1.ShowDialog() End Sub End Class

Pause for duration fails to resume.

  
Hello, In a site collection that has been upgraded from WSS 3.0 to SharePoint Foundation and have created a new list workflow in SharePoint Designer 2010 that has a 'Pause for Duration' step (set to 5 mins at this point for testing) and the workflow does not resume. When I create a similar workflow on a newly created site collection the workflow resumes with no issues. Looking into the database I can see that there is a row created for the pause step in the ScheduledWorkItems table and the Created Date/Time field is correct. Wereas the DeliveryDate seems to be doing something odd. At first it is set for the correct time to resume, but after that period the time is set for another 20mins, then after that period it is pushed back another twenty. It then stays like this and doesn't resume (I.E. at first the field is set to 2010-09-07 20:11:28.000, then to 2010-09-07 20:30:28.000, and finally to 2010-09-07 20:50:28.000). Whereas in the newly created site collection, in its content database the row is created in the ScheduledWorkItems table and deleted when the deliverydate time is reached and the workflow is resumed. A few notes: its a newly created workflow done is SharePoint Designer 2010, I had attempted to create list workflows in the past on this same site collection when it was wss3.0 with the pause for duration function but could never get it to resume - even

Background worker - errors in completed event

  
Create a new windows forms project (in using vb.net 2010). Create a button and a background worker on the form. Under the Debug > Exceptions menu, make sure that for 'Common Language Runtime Exceptions' you have 'Thrown' unticked and 'User-unhandled' ticked. Now put the following code in the form's code-behind; Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click BackgroundWorker1.RunWorkerAsync() End Sub Private Sub BackgroundWorker1_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork Threading.Thread.Sleep(2000) End Sub Private Sub BackgroundWorker1_RunWorkerCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles BackgroundWorker1.RunWorkerCompleted Dim X As Integer X = 5 / X End Sub End Class Why does it not error nicely? It comes up with no helpful stack trace and just says 'Exception has been thrown by the target of an invocation.'. Place the code to cause the error into the Button_Click event and run it and you will see the difference. Why do we not get these 'nice' errors given that the runworkercompleted event is supposed to be running on the main thread?

WPF: How to interact between UI thread and background thread?

  
our application needs us to do some heavy work on background thread. however, sometimes the background thread work needs user input to make some decision during the middle process. so we need to back the UI thread to get user input and then back the background thread to continue finish the heavy work. Is there example to show us how to interact bewtween UI thread and background thread? thanks, Jane  

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

  
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

Help with using a Background worker

  
Hi I am trying to use a background worker in my application.  I basically have a list of items displayed. When a user selects a particular item I have the background worker query the database to get information about the item selected and display it once it is done. (There are quite a few database calls) Since the database queries might take time, I have a UI wait animation displayed while the data is getting fetched. Once the background worker is completed I get rid of the wait animation and display the information fetched. This setup works fine if I do not click on any other item while the UI wait animation is being displayed. My main aim is to cancel the background worker from fetching the previously selected items information when a new item is selected (as the previous information would anyways be overwritten with the new item's information). The problem with such an approach is within the background worker's doWork method i would need to continuously check after each database query if the cancellation is pending and if it is then I can cancel the rest of the queries. I somehow feel this is not the right approach. If anyone has any suggestions about a better way to achieve the required functionality it would be great.. 

Error on datafilling in DataTable on background worker

  
I have got some error while datafilling from DataTable to Datagridview on BackgroundWorker... I saw some where that "Should not fill datatable while its working in Backgroundworker"... How can I manage this situation? Is there any possible logic to do that? Help me Sir,

Raising PropertyChanged on a background thread.

  
What's the official word from Microsoft on raising the PropertyChanged event on a background thread for a property that's bound to a WPF gui? A couple blogs/sites say that the event is automatically dispatched to the UI thread. I am able to verify this in my own my own tests. I can bind to a property on a view model and then set the property on a background thread without issues. I am able to verify that the property setter is called on a background thread; yet, the UI updates without issues. An example property:   private Brush _background; public Brush Background { get { if (this ._background == null ) { this ._background = Brushes.Blue; } return this ._background; } set { if (this ._background != null ) { Debug.WriteLine(Application.Current.Dispatcher.CheckAccess() ? "On UI Thread" : "On Background Thread" ); this ._background = value; this .OnPropertyChanged("Background" ); } } } If I set this property on a background thread, all backgrounds on controls bound to this property will change without problems. Any official word on this behavior?  

Background Thread + Impersonation + Termination

  

I have an ASP.NET 2.0 web application that is running in Windows Impersonation Mode...

Where the web site is configured as:

- Disable anonymous access

- and web.config

<authentication mode="Windows"/>
<identity impersonate="true"/>
    <authorization>
      <allow users="DOMX\USER1"/>
      <allow users="DOMX\USER2"/>
      <allow users="DOMX\USER3"/>
      <allow users="DOMX\USER4"/>
      <deny users="?"/>
      <deny users="*"/>
    </authorization>

This application needs to execute a potentially time consuming set of actions.  I had a couple of questions about using a background thread...

Question 1:   If I launch a background thread in the code behind... will that thread be terminated when the web application timesout?

Question 2:  If I decide to utilize a separate process (i.e. using System.Diagnostics.

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

  

Hi,

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 resume Sharepoint Designer workflow after Pause For Duration action

  
Hello we are using SharePoint server 2007 and developing workflows using SharePoint Designer.
Workflow in unable to resume after the time, set in the "Pause For Duration" action.
is there any Hotfix for SharePoint server 2007 to be installed on the server?

WPF 4 with SSRS Report Viewer and long running Background Worker Dispatch task.

  

Hello,

I've recently run into an issue with with WPF 4 and the SSRS viewer control with a batch emailing application. See http://www.jenasysdesign.com.au/dnn/Blogs/tabid/71/EntryId/5/WPF-4-SQL-Server-Reporting-Services-processing-application-Memory-Leak.aspx for details of some performance profiling issues I found with this technology stack.

I've got two issues.

Firstly, I implemented a background worker process to handling looping through the 2,800 reports. I found to run the SSRS report viewer to export the report results in a slow memory leak. See Red-gate Ants memory profiler 6 image in the link above. I'm not sure what I need to do to remove weak references with this combination of technology. Any ideas?

Secondly, the following code runs on the background worker process, designed so the user can monitor the progress of the a large batch of report files getting generated.  The catch here is involves using the SSRS viewer to export a reports results requires the Dispatcher.Invoke method to ensure that ReportViewer.xaml screen gets a UI thread, but in the process it interferes with the background workers report progress methods, so the UI doesn't see the progress.  

WPF 4 with SSRS Report Viewer and long running Background Worker Dispatch task.

  

Hello,

I've recently run into an issue with with WPF 4 and the SSRS viewer control with a batch emailing application. See http://www.jenasysdesign.com.au/dnn/Blogs/tabid/71/EntryId/5/WPF-4-SQL-Server-Reporting-Services-processing-application-Memory-Leak.aspx for details of some performance profiling issues I found with this technology stack.

I've got two issues.

Firstly, I implemented a background worker process to handling looping through the 2,800 reports. I found to run the SSRS report viewer to export the report results in a slow memory leak. See Red-gate Ants memory profiler 6 image in the link above. I'm not sure what I need to do to remove weak references with this combination of technology. Any ideas?

Secondly, the following code runs on the background worker process, designed so the user can monitor the progress of the a large batch of report files getting generated.  The catch here is involves using the SSRS viewer to export a reports results requires the Dispatcher.Invoke method to ensure that ReportViewer.xaml screen gets a UI thread, but in the process it interferes with the background workers report progress methods, so the UI doesn't see the progress.  

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

A query regarding the MSDN library background worker example

  

In the MSDN library article "How to: Use a Background Worker",

(see http://msdn.microsoft.com/en-us/library/cc221403(VS.95).aspx),

the following sample code is presented...


Private Sub bw_DoWork(ByVal sender As Object, ByVal e As DoWorkEventArgs)
    Dim worker As BackgroundWorker = CType(sender, BackgroundWorker)

    For i = 1 To 10
        If bw.CancellationPending = True Then
            e.Cancel = True
            Exit For
        Else
            ' Perform a time consuming operation and report progress.
            System.Threading.Thread.Sleep(500)
            bw.ReportProgress(i * 10)
        End If
    Next
End Sub

For what purpose has the "Dim worker as..." statement been included in this code?

Siggy


Handling API events in a background thread

  

Hello,

I am in the planning stages for developing a VB.Net class (I am using VS 2008) that is to obtain data via an API provided by a COM object (AxInterop.TWSLib) making requests to an Internet server. The API provides data via events. The class should do its work on a separate thread; it takes several seconds (sometimes up to ~10) to collect the desired data. One should be able to instantiate several instances of the class in order to collect data in parallel. The class would be given a reference to the TWSLib object when its constructor is called, as well as several parameters. There needs to be a way for the class to provide results, preferably in the form of a generic list.

I have succeeded creating multithreads using the backgroundworker approach. From what I have read, though, that does not appear to be the appropriate approach when the background thread is supposed to wait for events to handle. I have not tackled more advanced multithreading approaches. Studying VS 2008 documentation on Threading, ThreadPool, delegates, etc. has not yet given me an idea how to design a class that handles those API event

While processing large cubes, various file system errors: "the background thread running lazy writer

  

 

We consistently get these I/O errors when processing large OLAP databases.  After a reboot, I can usually get a database to process a few times, but then suddenly reprocessing will fail with errors similar to the one shown below, when nothing changed (no data or structure changes).  The specific file(s) it reports are always different.  Also, sometimes it crashes the msmdsrv.exe process, which seems to intermittently affect other server functions as well (killing the ability to RDP into the server, or the ability to open Event Viewer).

 

<error message>

File system error: The background thread running lazy writer encountered an I/O error.
Physical file: \\?\D:\OLAPData\SSAS1\SA1.166.db\SA1 Data Source View 1.238.cub\Fact Subject.231.det\Fact Subject.221.prt\271.Aspect.Source Key.fact.map.hdr.
Logical file: .
File system error: The following error occurred while writing to the file 'LazyWriter Stream':
Insufficient system resources exist to complete the requested service. .
File system error: The background thread running lazy writer encountered an I/O error.
Physical file: \\?\D:\OLAPData\SSAS1\SA1.166.db\SA1 Data

Categories: 
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