Creating A Progress Bar That Runs On Another Thread While Keeping Calculation In Main Thread

Nov 12, 2009

Preface: I know this is an unusual/improper way to do this. I can do this with a "real" ShowDialog(), background worker/thread, and so on. I am trying to do specifically what I describe here, even if it is ugly. If this is impossible for X reason, I have created a fancy progress dialog for some of our long running operations. I need to have this dialog shown on a new thread while having processing continue on the calling (UI in most cases) thread.

[Code]...

View 3 Replies


ADVERTISEMENT

Threading Progress Bar In .net - Thread Operation Not Valid Control 'ProgressBar1' Accessed From A Thread Other Than The Thread It Was Created On

Feb 17, 2012

Would anyone be able to help me here please. I'm fairly new to VB.net and threading so im just trying to figure out what is happening.When I debug this I am getting the error thread operation not valid: Control 'ProgressBar1' accessed from a thread other than the thread it was created on.

I'm a little lost as to why the error is occuring or how to fix it. I've had to put the progress bar in a separate thread otherwise the GUI crashes

[Code]...

View 2 Replies

Access Progress Bar On Main Form From Thread On User Control?

Aug 18, 2009

I have a windows application with a main form, on which a user control is added dynamically when a device connects trough USB.

On a user control, there is a thread wich is getting data from the device trough USB and when it is finished, I want to change a progressbar that is located on the main windows form where user control reside.

This is the code that is I call on the user control thread to change the progress bar value:

Frm_Main.UpdateProgressBar(CInt((AllBytesReceived / MaxBytesInFlash) * 100))
and this is a code that is called on the main form:
Private Delegate Sub UpdateProgressBarDelegate(ByVal value As Integer)

[Code]....

View 8 Replies

Write In Worker Thread In A Data Table And Rich Text Box in Main Thread

Mar 4, 2009

I'm creating a Client Server application which involves theServer running some scripts in clients and getting back results in an automated way. In Server, other than Main thread, i have 2 worker threads, a) one monitoring response from clients and b) the other scheduling next available job to respective client which executes that job. The issue here is ,I want these worker threads to write the status of their work in the UI(which comes under Main Thread). Also i need to write things in worker thread in a Data table and Rich Text Box in Main thread. But, I can't do so, since it has been blocked to access one thread's function or property directly from others. Is there any work around to do this?

View 8 Replies

Thread State - Thread In An Application Which Calls A Sub Routine Main()

Jul 26, 2010

I have a thread in an application which calls a sub routine Main(). The Main sub routine in turn call several sub routines/functions from with the same module,several different classes in the same application. Also some sub routines/functions call routines from a class library. Now say the routine/function in class library goes into a infinite loop and never returns. I would like my thread in the application to raise a event and display message to the users about the infinite loop. I am giving some sample code for the application.

Imports System.Threading

Module VMain
Public gbSuspend As Boolean

[CODE]...

View 7 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

Fire An Event In Main Thread From Another Thread?

Sep 24, 2009

could someone tell me how to fire an event in main thread from another thread as well as fire and forget without use a new thread?

View 9 Replies

Run A Method On The Main Thread From A Separate Thread?

Dec 31, 2010

I'm reading data from a serial port, but the DataReceived event of SerialPort is handled on it's own thread. I want to handle this on the main thread, but simply declaring an event and raising it still results in it being processed on the SerialPort thread. I'm assuming I need to declare a delegate I can call, but I don't see how that would work.

For example, I want to call Sub HandleDataReceived() on the main thread from the DataReceived thread, having HandleDataReceived() run on the main thread. How would I do this?

View 1 Replies

VS 2010 Error - Cross-Thread Operation Not Valid: Control TbPlaca1 Accessed From A Thread Other Than The Thread It Was Created On

Aug 13, 2010

In one application, I need use 4 simultaneous threads.When the threads finished, I need to update the text of a TextBox.So, I create 4 Textbox, and I wanna the threads change the text to FINISHED.Each thread change one distinct TB.I use this "example"

Dim Terminados As Integer = 0
Private Sub frmEnviarMensagem_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Timer1.Enabled = True
Timer1.Start()

[code]....

The problem is, I have an error in the red lines.The error is: INVALIDOPERATIONEXCEPTION "Cross-Thread operation not valid: Control tbPlaca1 Accessed from a thread other than the thread it was created on."I don't use cross threading. Each TB only was accessed for the correspondent thread, and for the "main program".

View 3 Replies

Cross-thread Operation Not Valid: Control 'Panel1' Accessed From A Thread Other Than The Thread It Was Created On." ?

Nov 3, 2011

This is the error message I am getting:

"Cross-thread operation not valid: Control 'Panel1' accessed from a thread other than the thread it was created on." The reason I am getting this error is because I am opening up a new form and then calling these three things:

Panel1.Show()
Label1.Show()
Label2.Show()

why I get this error message because it doesn't occur normally if I open Form2 after closing Form1, it only occurs when I open Form2 after closing Form4.

View 4 Replies

Error - Cross-thread Operation Not Valid: Control 'txt1' Accessed From A Thread Other Than The Thread It Was Created On

Jul 21, 2009

I have done a program using vb2005 to display reading from my microcontroller bs2 board but have encountered some problems. My code are as follows.

Dim Stop_Rx As Boolean
Private Sub btnRead_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRead.Click
SerialPort1.Open()

[code]....

I've encounter an error which is, (Cross-thread operation not valid: Control 'txt1' accessed from a thread other than the thread it was created on.)

View 7 Replies

Error : Cross-thread Operation Not Valid: Control 'l_users' Accessed From A Thread Other Than The Thread It Was Created On

Jun 21, 2012

When my client try to connect to server I'm getting this error : Cross-thread operation not valid: Control 'l_users' accessed from a thread other than the thread it was created on.

Private Sub _socketManager_onConnectionAccept(ByVal SocketID As String) Handles _socketManager.onConnectionAccept
l_Users.Items.Add(SocketID)
End Sub

View 3 Replies

Waiting For Threads - Thread.join Suspend Execution Of Code On Calling Thread Until Spawned Thread Finishes Or Is Aborted

Sep 2, 2010

My understanding is that thread.join will suspend the execution of code on the calling thread until the spawned thread finishes or is aborted...

With that in mind, I tried this:

For i = 1 to 50
threads = New Thread(AddressOf test)
threads.IsBackground = True
threads.SetApartmentState(ApartmentState.STA)

[CODE]...

However, the rest of the code runs when the loop finishes, not waiting for all the spawned threads to finish. Since the rest of the code needs the threads to finish (otherwise the rest will error).

View 4 Replies

Cross-thread Operation Not Valid: Control 'Autocad' Accessed From A Thread Other Than The Thread It Was Created On

Jun 6, 2010

I have written an application that loads a form - frmCad as well as AutoCad. It does this via a class which detects when AutoCad quits.

Friend Class CadApp Private WithEvents AppObject As AcadApplication... Private Sub AppObject_BeginQuit(ByRef Cancel As Boolean) Handles AppObject.BeginQuit RaiseEvent Quit() End SubEnd Class

My main class loads frmCad as well as CadApp.

Public Class Cad Private WithEvents frmCad As CadForm Private WithEvents app As CadApp... Public Sub ShowForm() If frmCad Is Nothing Then frmCad = New CadForm frmCad.Visible = True End Sub... Private Sub app_Quit() Handles app.Quit frmCad.Dispose() frmCad = Nothing .... End Sub

When I debug the program, it stops at frmCad.Dispose()The program continues to execute, but all the code after it fails to work.Looking more carefully I get an error message which contains:-Cross-thread operation not valid: Control 'Autocad' accessed from a thread other than the thread it was created on.

View 4 Replies

Cross-thread Operation Not Valid: Control 'label2' Accessed From A Thread Other Than The Thread It Was Created On?

Feb 9, 2011

My error:Cross-thread operation not valid: Control 'label2' accessed from a thread other than the thread it was created on. I want to be able to give my Public RunBot() sub access to edit Labels, buttons, etc without an error.

[Code]...

View 8 Replies

Cross-thread Operation Not Valid: Control 'lblStatus' Accessed From A Thread Other Than The Thread It Was Created On

Apr 1, 2010

I'm getting the 'System.InvalidOperationException' error on acccessing a thread from other than where it was created. My code is:

'Required by the Windows Form Designer
Public components As System.ComponentModel.IContainer ' changed from private

[code]....

View 3 Replies

Cross-thread Operation Not Valid: Control 'statusHO' Accessed From A Thread Other Than The Thread It Was Created On

Jun 6, 2009

My problem is Cross-thread operation not valid: Control 'statusHO' accessed from a thread other than the thread it was created on.

System.InvalidOperationException was unhandled
Message="Cross-thread operation not valid: Control 'statusHO' accessed from a thread other than the thread it was created on."
Source="System.Windows.Forms"
StackTrace:

[Code]...

i used it and it works fine then. but as it is mentioned its not a good practice to use it. So what should i do? is it ok if i use this as i am not able to use correct practice. Mine application is not for enterprise purpose. its just my class project, and it works fine even if i put application working in background. System works ok. I dont know how to correct this error.As i dont have that much knowlege of threads.

So please guide me how to fix this in correct way otherwise i am force to go for bad programming practice
Please refer to Windows Mobile Developer Center > Smart Device Development Forums > Windows Mobile Development > Appendtext not working for all my code details

View 1 Replies

Cross-thread Operation Not Valid: Control 'lv1' Accessed From A Thread Other Than The Thread It Was Created On?

Aug 4, 2009

Cross-thread operation not valid: Control 'lv1' accessed from a thread other than the thread it was created on.

Dim lvi As ListViewItem
For Each lvi In lv1.Items

[code]....

View 1 Replies

Error Saying "Cross-thread Operation Not Valid: Control 'lblOnline' Accessed From A Thread Other Than The Thread It Was Created On."?

Feb 7, 2011

Ok i have a Form with the following

Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
txtNotepad.Text = LoadFile("notes.txt")

[code].....

View 12 Replies

Starting Up A Thread That Runs The Standard Windows Defrag Utility?

Apr 8, 2009

I have a app that is starting up a thread that runs the standard windows defrag utility. It also gives the user the option to cancel the defrag if they want to. Problem is if the thread defrag is running on is canceled is there any data loss or does it just do the last operation and then exit. For example the code goes something like this:

[Code]...

Code works exactly as it should, runs the defrag on a separate thread so my UI remains responsive. I'm just worried about the effect of the cancel on it, when you call a thread abort does the program running in the thread know it's being canceled and "cleanly" close? I don't want to abort a file move operation when it's defraging and end up with a corrupt file.

View 11 Replies

Run Task On Main Thread?

Mar 23, 2011

I have an application that displays real time data. Queries are made to a MySQL database on another PC over the internet every 10 seconds to gather the most recent data.Originally I did the query within a BackgroundWorker so that the GUI is still responsive while the query is answered. However, I found that I need a timeout on the database query (as sometimes it hangs without generating an error) and couldn't do this within the background worker.

So now I'm trying to do it with threads. I have managed to run a thread to get the data.I need to understand how to run a task on the main thread when the GetDataThread is complete. If I do this using Events as shown below then Sub GetDataComplete is running as part of the GetDataThread not the Main Thread. I want to run a sub like backgroundWorker1_RunWorkerCompleted (this seems to run on the main thread).

My Main thread is called MainThread

VB
Imports System.Threading
Imports System.ComponentModel

[code]....

How can I run a task on the main thread when the GetDataThread is complete.

View 9 Replies

VS 2005 - Progress Bar - Is That Following A Thread

Dec 14, 2009

I would like to get a progress bar to actually follow the work being done in my application. In other words I load application and then the user loads a database by clicking file open etc... I would like to have a progress bar run until the data file and all text and labels are completely loaded Is that following a thread? forgive me if I am way off, still learning

View 4 Replies

Marshal Back To Main Thread?

Dec 15, 2009

I am using a COM library in my VB.NET app that has an asynchronous execution method and signals my application via an event when it completes. The event handler is on a different thread from the calling thread. I want to invoke another execution on the main thread when I receive the completion event. If I call directly in the event handler for another execution it starts on the new thread. How do I marshal back to the main thread. This is done in a dll not in a form.

View 3 Replies

Notifies The Main Thread Via A Delegate Sub?

Mar 3, 2012

i have a background thread when it is done doing its task it notifies the main thread via a delegate sub it seems if the main thread is "busy" then the background thread hangs waiting for the main thread. if this is normal, which i assume it is my background thread, starts another thread, and this 2nd background thread makes the delegate call is this bad practice?

View 2 Replies

Pass A String To The Main Thread?

Jul 14, 2011

I have written a program that performs multiple httpwebrequests. It reports in to me by writing to the console. In the past, i have used a backgroundworker for this task, but the code became ugly and bulky. Now, i use threading.thread to start the background process. However, i can't seem to find an explanation on updating the UI from the worker thread.

I've read a lot on delegates, invoke and lambda's, and i just got more confused.

Let's say, in my current program i have this line to be displayed in a textbox on my main form:

"Error reading events!"

View 2 Replies

Using A Timer To Delay Main Thread?

Feb 3, 2011

is the first time I tried to use a timer - can't understand why it doesn't work!I need to suspend the main thread for a preset time 'delaymSecs' then let the thread continue.I tried this code fragment:-

System.Timers
'(etc)
Public

[code].....

View 1 Replies

[2008] Running In Main Thread?

Mar 2, 2009

Well basically I have something being done in a new thread and I would like to start a sub not in the same thread, but in the main thread. How do I do that?

View 3 Replies

Running A Progress Bar On A Separate Thread?

Apr 11, 2012

I've made an application which goes through a long procedure when a button is clicked. I don't want the user to think the program has frozen, so I'd like to add a marquee progress bar just to show that it's still running. However, if I simply add the progress bar and make it visible when the button is clicked, the bar will appear but freeze and wait for the procedure to finish before it starts scrolling.

I know this is due to both the procedure and the progress bar running on the same thread, but the tutorials I've seen on getting a process to run on another thread seem confusing. What is the simple way to make a progress bar run on a separate thread?

View 12 Replies

Separate Thread Accessing To Main Ui Controls?

Aug 25, 2009

how to access the main ui's labels from a delegate method?

View 7 Replies

Background Worker Create Second Thread For Progress Bar?

Apr 6, 2011

I have searched the forum and found several forums related to the backgroundworker thread but have been unsuccessful in finding my answer.My objective is to display an animated gif or progress bar while the program is executing a particular method which can take upwards of several minutes to complete. I cannot get the second thread to run the progress bar while the main progrem is executing the time consuming method. I have created a demo based on another thread and can't seem to get it to create two threads. I was attempting to get the backgroundworker to execute the progress bar while my main code runs on UI thread.

[Code]...

View 10 Replies







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