Winform Application Based On BackgroundWorker Thread Concept / UI Update

Jan 26, 2012

I have build a VB.Net windows application which does uploads data into database and basically updates two controls:

1. A textbox which is constantly updated with one line per database record upload.

2. A label which keeps track of the count of database record uploaded.

I have used BackgroundWorker thread concept, where the thread's bgwWorker_DoWork() method contains the business logic for upload and bgwWorker_ ProgressChanged() updates the 2 UI controls based on uploads.But the issue I am facing is that I do not get complete updates on both the UI controls. Sometimes the thread bypasses update of textbox and sometimes of label. I could resolve this issue by adding System.Threading.Thread.Sleep(25) before each UI control update code.[code]

View 2 Replies


ADVERTISEMENT

VS 2010 Backgroundworker Thread Running Faster Than The UI Can Update Progress?

Nov 15, 2011

I have a VB.NET 2010 app that uses a backgroundworker to process MS Word docs. All of the code does what it is supposed to do, except when my code calls ReportProgress(). The UI cannot process the ProgressChanged event fast enough before the values in the class that are passed are changed. I know this because I inserted a System.Threading.Thread.Sleep(100) line after each ReportProgress() call which allows time for the UI to make the updates properly. I guess I am looking for a better solution thanThread.Sleep(100) since this adds to the amount of time it takes to process all of the files. Here are some snippets of code that I am using:

[Code]...

View 5 Replies

Update The Button Text On A Form From A Backgroundworker.do_work Event, And It Failed With The Usual Cross-thread Exception Message?

Nov 14, 2011

I tried to update the button text on a form from a backgroundworker.do_work event, and it failed, with the usual cross-thread exception message.However, by pure chance, I also tried to update text in a system.windows.form.toolstripstatuslabel also from this backgroundworker.do_work event, and it DOES work. Question: why is this? Is it perhaps because theres some kind of implicit shared behaviour with system.windows.form.toolstripstatuslabel?

View 4 Replies

.net - Update Statement Updates 0 Rows Via The C# Winform Application?

May 29, 2010

I'm trying to update a row via c# winform application. The update query generated from the application is formatted correctly. I tested it in the sql server environment, it worked well. When i run it from the application i get 0 rows updated.Here is the snippet that generates the update statement using reflection - don't try to figure it out. Carry on reading after the code portion:

public void Update(int cusID)
{
SqlCommand objSqlCommand = new SqlCommand();
Customer cust = new Customer();

[code]....

The above final update statement works on the sql environment, but when running via the application, the execute non query runs ok and gets 0 rows updated!

View 2 Replies

Possible To Achieve Performance Tuning With Same Thread Concept?

Apr 26, 2011

We have developed a vb.net application using multi-threaded listener concept and a dedicated thread for each folder to monitor. With that we simultaneously keep track of the incoming files in each folder.Currently, we are facing an issue whenever we receive multiple files of bulk volume, parallel processing of the files getting delayed with thread concept or failing sometimes.We need to implement the same logic with some other concept avoiding multi-hreading. Or is it possible to achieve performance tuning with the same thread concept?

View 2 Replies

BackgroundWorker Thread Communicate With The Primary UI Thread When Encapsulated In A Class?

Jul 1, 2010

A BackgroundWorker thread can pass data to the primary thread. It does it via the RunWorkerCompleted and ProgressChanged events, which I believe run in the primary thread. I would like to encapsulate the BackgroundWorker control in a class so that I can instantiate it more than once. But I don't know how the BGW can then communicate with the primary thread. If the BGW control is within a class, it does not have access to the properties outside the class. In that case, how can the BGW pass data to the thread that instantiated it?

[Code]....

View 3 Replies

Access Objects Of Main Thread From BackgroundWorker's Thread?

Aug 4, 2011

I'm working with BackgroundWorker, I want the BackgroundWorker do the retrieval process of data from database while the user can still do another task on the form. The problem is, after retrieving the data, I can't seem to access the ListView in my Form from the DoWork event of BackgroundWorker, I will populate that ListView using the data I've retrieved.

Consider this example, this is how I'm doing it:

Public Class Test
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

[Code].....

View 1 Replies

Forms :: Run Processes Synchronously From A Thread Or Backgroundworker Thread?

Sep 4, 2009

How do run processes synchronously from a thread or backgroundworker thread? Is it even possible?We have program that allows the user to download several files from a remote server, compress them, and then email the files.It has several long running processes that must run in order. We want these to run on a separate thread so as not to make the form unresponsive. Does a way exist to do this? We attempted a rather clumsy way of approaching this problem by using background worker threads. When each thread is completed and returned back to RunWorkerCompleted, we start another background worker thread and repeat the the next process. It works somewhat but seems to take a lot of resources to run.

View 1 Replies

Set Attributes Of Entry Point Thread Of A Form Based Application Before It Start?

Mar 13, 2010

I do not want to disable Application Framework feature and turn to main function technique

View 1 Replies

Winform Progress Loading With Backgroundworker?

May 22, 2012

trying to show 'loading' text while performing selectedindexchanged with backgroundworker

but it is hang in 'loading' and result does not show :(

Private Sub cbPortNo_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbPortNo.SelectedIndexChanged

[Code]...

View 2 Replies

C# - Get The GUI Thread Of Winform?

Feb 1, 2011

I have a winforms app with multiple GUI threads. I want them to be able to access each other's thread objects without having to keep track of that information separately.Is there a function in .NET that I can feed a winforms control or window object, and get back the thread? Or a function in the API I can pinvoke for the threadID?

Edit For those of you who for some reason believed my italicized text, congratualations, you're hired!! Here is the problem: "App is crashing in the wild by locking up totally, that is, it stop responding. Very intermittent, and trying to debug it, it seems to never happen."

So what do do? Install an option in the program that the user can activate under our direction, whereby from another GUI thread in the same app, do a thread.abort on the main GUI thread, then we can look at the call stack in the error log. Viola, found an impossible to debug error in less than a day. (Stop now, it had nothing to do with abusing multithreading:-)

I'll admit I almost didn't ask this, the reason I did was I could see an object reference to the main form, but there wasn't any for its thread. I'm giving Chris Shain the answer a/c it is a quick way, unfortunately when the thread is hanging, I wouldn't be able to do an invoke (it would hang too). A little more digging revealed the GetWindowThreadProcessId API call. But it's an unmanaged thread ID, apparently there are complications turning that into a managed thread ID.

So I bit the bullet and put in a global reference to the main UI thread. Would have posted it to begin with, but hadn't written it yet.In main public module/static class:

Public GUIThread As Threading.Thread
Sub Main()

[code]....

View 3 Replies

Backgroundworker Return Value To Another Thread?

May 2, 2009

I am using a class with below code, the question is how to update the label's value at UI thread from the backgroundworker?

Imports MySql.Data.MySqlClient
Public Class clsBackGroundWorker

[code]....

View 7 Replies

Cross Thread With A Backgroundworker?

Jan 27, 2010

im sorry if this has been asked before.but i couldent find it in my first look i have a form that runs a query on a mysql database but as it runs the query the form stops responding till it finishes sooo i had the smart idea of putting it in a back ground worker..

GREAT i thot i had it working it all seemed to go greeat then i noticed when i try to change the label text on the form to corispond to the info it got... it wont work it give me a cross threading error....

how to cross thread between the back ground worker and the origial form..

View 2 Replies

How To Sleep Thread Of BackgroundWorker In WPF

Jul 29, 2009

I wanna sleep a second thread of BackgroundWorker. I tried to use Me.Dispatcher.Thread.Sleep(500) in DoWork event, but it fails.

View 3 Replies

VS 2008 BackgroundWorker Vs Thread

Apr 17, 2012

I have some classes right now that I have that I reuse for Client/Server programming. I'm using Thread in these classes though for monitoring for things being written to the network streams and stuff like that. I'm just not sure if I should be using the background worker class instead. I'm also using TCPClient and Listener classes, should I be using sockets directly? I guess it would all depend on the flexibility I would need in a given application's specs.

[Code]...

View 3 Replies

.net - Cross Thread Operation On WinForm Controls?

Sep 8, 2010

In main thread I create panel(s) (based on some configuration), and then in the next step based on the file type (like video, ppt, image...) I create appropriate controls (dynamically) to show on the forms.

The creation of the control will be done in separate threads (for each file). After creating the control, it throws an error when I try to add that control to the panel (which was created in the main thread), something like cross thread violation, control was accessed from one thread other that it was created.

Can some one please help me in this regard? In this scenario, everything - creating the panels and controls - will be dynamic. Nothing will be static.I tried some of the articles found here on StackOverflow (like, control.BeginInvoke() .. etc), but wasn't able to solve my problem.

View 2 Replies

Close Winform Dialog Box From A Event On A Different Thread?

Apr 1, 2011

I actually have gotten the events firing like I expect except for trying to close the dialog window.

Background: I have a wrapper around my "Jabber Client" that sets the delegates for the client wrapper and basically generates a messageProcess event. This event is wired in the main program Class[code]...

View 4 Replies

.net - Sane Number Of BackgroundWorker Thread?

Apr 27, 2011

I am writing an 'Admin Console' that accesses hMailServer via its provided COM interface. I am using Visual Basic 2010 Express. In one procedure, it scans for the whole accounts. Because it's a lengthy procedure, I shove it into a set of BackgroundWorker threads.

First result: A maximum of 19 simultaneous threads, with 36 seconds total time.Then I rewrote a time consuming thread initialization code segment, and managed to reduce the time required to approximately 14 seconds... but the thread count now hit 330 threads!Will that huge amount of threads be detrimental? E.g., causing out-of-memory exceptions &c. ?

View 1 Replies

BackgroundWorker Get Values From UI Thread While It Is Running?

Jan 2, 2012

I am using the BackgroundWorker to do the heavy tasks so the UI thread doesn't get blocked. While the BackgroundWorker can send values to the UI thread using the progress-scheme, how can the BackgroundWorker get some values FROM the UI thread?

Either by asking it or simply by the UI thread sending some values to the BackgroundWorker?

Just accessing a variable of the UI thread like UIForm.x within the BackgroundWorker does not work, it does not seem to have access to the UI variables?

View 1 Replies

Backgroundworker Thread Causing UI To Hang?

Aug 29, 2010

I have a background worker that's checking the status of four services on a remote server.This is setup on a timer (5 Seconds) as below. For some reason it's hanging the UI thread causing the application to 'lock' for a second each tick, I cannot work out why?!

Private Sub ServiceTimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ServiceTimer.Tick
_ServiceBGWorker = New System.ComponentModel.BackgroundWorker()

[code]......

View 2 Replies

Sendkeys On Backgroundworker Thread Not Working?

Mar 29, 2010

Well to simplify it, whenever I use sendkeys from a background thread it just doesn't work. I even created a textbox, button, and backgroundworker with the following code:

Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

[Code].....

View 4 Replies

VS 2008 BackgroundWorker Thread An Updating UI?

Apr 3, 2010

I'm running some tasks on a BackgroundWorker thread and needed to display the current tasks in a label.Before adding the label, the tasks were completing just fine and the UI was responsive.Once I added the labels, the UI has become unresponsive. The issue, I believe, is the Invoke property.I've declared all my tasks, including the updating, in a sub and am getting the Invoke property of the label each time, in order to set the information.The following is an example of what I'm doing:

VB.NET
Private Sub Test()If lblTask.InvokeRequired = True Then Dim mi As New MethodInvoker(AddressOf Test) lblTask.Invoke(mi)

[code]....

View 7 Replies

Backgroundworker - Cross-thread Operation Not Valid

Jun 13, 2010

Yes, I see what you mean. But I had to do it that because I tried to do it this way:

CODE:

but its says "Cross-thread operation not valid: Control 'RichTextBox1' accessed from a thread other than the thread it was created on."

View 1 Replies

C# - Difference Between BackgroundWorker And System.Threading.Thread

Oct 24, 2009

What is the difference between creating a thead using BackgroundWorker and creating a thread using System.Threading.Thread?

View 2 Replies

Forms :: New Thread Versus BackgroundWorker Updating UI

Aug 24, 2010

i have lurked on these forums before and finally signed up..i have a situation that, after days of searching the web, i have not been able to come up with a solution for.i have to fire off a function that takes a large amount of time (writes to database, creates files, etc etc)this function is a non-shared function of a class. if need be i could make it Shared.[code]the code works great, but what i need to be able to do is update a form with a progress bar as the job is processing.all of the examples i have seen that do this are being called from within a Windows Form and they access the form directly - i cant do that in this case. my form needs to be 1 form for 1 job being executed - can process multiple jobs at one time and thus i need multiple forms.i have tried making the form part of my delegate class but since it runs in the same thread the effect is it "freezes" until the job is complete.i have just started looking into using a background worker but again, all examples i have seen use the component as part of a form - that wont work for me.

View 3 Replies

VS 2008 Add Information To A ListView From A BackgroundWorker Thread?

Nov 30, 2009

I'm trying to add information to a ListView from a BackgroundWorker thread. I thought I could do this in this manner:

vb.net
Private Delegate Sub _ListView(ByVal lvi As ListViewItem)
Public Sub test(ByVal lvi As ListViewItem)

[Code].....

When I attempt to run the "test" sub the BackgroundWorker, I get an error:

Argument not specified for parameter 'lvi' of 'Public Syb test(lvi as System.Windows.Forms.ListViewItem)'.

Is there something I need to specify when declaring the sub, or in the sub itself?

View 8 Replies

VS 2008 Updating A ListView From A BackGroundWorker Thread?

Sep 20, 2009

I'm using the following to check the state of checkboxes and then activate some public subs based on the checked state of the checkboxes:

vb.net
Public Sub TestSub() If Me.CheckBox1.InvokeRequired Then Me. CheckBox1.Invoke(New MethodInvoker(AddressOf TestSub)) Else Begin() End If End Sub

Within the Begin sub, I have code that performs specific actions and then updates a ListView with that information.As far as I can tell, the actions are being performed, but the ListView isn't being updated with the info.I'm calling the Test sub from a seperate form, within the BackGroundWorker's DoWork event.Would I have to check the InvokeRequired property of the ListView as well?I'm looking more into the documentation of the BackGroundWorker.

View 8 Replies

Wpf - Kill A BackgroundWorker In .net If Thread Hangs Using COM Object?

Jun 10, 2012

I have an application that interacts with third party COM objects. A method of the COM object that I call will sometimes stop responding. I created a Backgroundworker thread to call the function and I am trying to monitor it from my main thread to kill it if it hangs. I have additional code (not supplied) that tracks the processing time using system.timer from the main thread and I raise an event if it exceeds my threshold (this part is fine). This is when I want to kill the thread and stop code execution. The problem is.. if I use the cancelasync method it will just pend since the code execution is stuck on the function call.

The particular function call in the code snippet that hangs is "objCOM.SendDataToServer()". It typically takes 1-3 seconds to return, but if it gets no response it will just hang indefinitely and won't return at all (no errors just hangs).. there is no timeout... and since I don't have access to the source function I cannot supply one. I tried the .dispose() method of the thread, but apparently that doesn't kill it and neither does cancelasync. I just need help figuring out how to KILL this thread so I can reset the server connection and call the function again.

Public Class COMobject
Private objCOM as new acs.manager
Public Sub CallComFunction()

[code]....

View 1 Replies

.net - Events Raised By BackgroundWorker Not Executed On Expected Thread

Mar 22, 2010

A winforms dialog is using BackgroundWorker to perform some asynchronous operations with significant success. On occasion, the async process being run by the background worker will need to raise events to the winforms app for user response (a message that asks the user if they wish to cancel), the response of which captured in an CancelEventArgs type of the event.

Being an implementation of threading, I would have expected the RaiseEvent of the worker to fire, and then the worker would continue, hence requiring me to pause the worker until the response is received. Instead however, the worker is held to wait for the code executed by the raise event to complete.

It seems like method I am calling via the event call is actually on the worker thread used by the background worker, and I am surprised, since I expected to see it on the Main Thread which is where the mainform is running. Also surprisingly, there are no cross thread exceptions thrown.

View 1 Replies

Creating A Webbrowser Control In A Background Thread In Backgroundworker?

Sep 23, 2009

Is it possible to create a WebBrowser control in a background thread in BackgroundWorker?

Private Sub BackgroundWorker1_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
Using web1 As New WebBrowser[code].....

Does anyone know a way to create a background WebBrowser? I would like to do it to extract info from websites then spit out the various HTML DOM arrays

View 4 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved