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


ADVERTISEMENT

C# - Background Worker In External Reference (DLL) Locking Main Thread?

Mar 21, 2011

I use background worker almost daily and works great. Today I came to an instance though where I needed to put my background worker in a separate project then the one I was running because I needed to use this class in two different projects in my solution. When I tested the coding on a winforms form, it works perfectly, handling my coding on the background thread. When I try to reference this class from an external project, all of my coding seems to run just fine, but it does not appear to be doing anything on a background thread as it should be, causing my main window to lockup.

Is there any way around this / what is the best practice for ASYNC calls in an external class.Note I basically created a class that u call start, and an event fires when data is ready, so it's not like my external project is waiting for the method to complete.

Solution ABC has two projects. Project A and Project B. Project A is my WPF application and B is my DLL doing the work. Inside project A I have

Dim SmartCardData as new Solution.B()
SmartCardData.Start()
Project B has a sub

[code]....

View 3 Replies

VS 2005 Class Api Needs To Get A Handle On Form Elements In The Main Worker Thread

Sep 4, 2009

I have a standard windows application called winap. I have a com component which acts as an api to the winap. I have a class in winap call classapi which has all the methods that the api calls and all works well. The problem is that one of the methods in my class api needs to get a handle on form elements in the main worker thread. Whenever I try to access an existing form I keep getting null because the for exists in the main worker thread and my api call is in a seperate thread.

[Code]...

View 5 Replies

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

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

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

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

Wpf :: New To MVVM - Separating Data Processing Thread And UI Thread?

Mar 29, 2010

I have a program that tracks packages. Shipment and package entities are persisted in SQL database, and are displayed in a WPF view. Upon initial retrieval of the records, there is a noticeable pause before displaying the new shipments view, and I have not even implemented the code that counts shipments that are overdue/active yet (which will necessitate a tracking check via web service, and a lot of time).I have built this with the Ocean framework, and all appears to be doing well, except when I first started my foray into multi-threading. It broke, and it appeared to break something in Ocean... Here is what I did:

Private QueryThread As New System.Threading.Thread(AddressOf GetShipments)
Public Sub New()
' Insert code required on object creation below this point.

[code].....

View 1 Replies

Error On Worker Thread

Dec 27, 2009

I have some class that splits some work onto multiple worker threads. To be more specific: the class represents a download, that can have as many segments as the user wants, that get then put onto separate threads.When I run the download with one segment, it works fine. When I run it with 2 segments, the second segment encounters an error.[code]When I put a breakpoint on the if, it'll stop there, but when I go to the next line, I get an error.I don't get what's getting wrong, and got a headache after a few hours of attempting to keep track of the correct thread.Anyone an idea what's going wrong, or how I can detect it better? (This is the first time I'm doing real multi threading debugging.

View 4 Replies

Updating UI From Worker Thread

Oct 27, 2009

This is slightly different to just updating a UI from a worker thread. The object which calls the thread, calls another object, and it is this object which is is trying to update the UI. It doesn't however work.

Imports System.Threading
Public Class Form1
Public Delegate Sub GetText(ByVal sText As String)
Public GetSomeText As GetText
Public Sub New()
' This call is required by the Windows Form Designer.
[Code] .....

View 5 Replies

C# :: Co-ordinating Worker Thread Shutdown?

Nov 1, 2011

I've got a List(Of IWorker) which contains a number of concretes. IWorker in turn has a Startup() and Shutdown() method.Inside the Worker class, Startup() creates a new worker thread then returns. Shutdown() presently sets a private ShutDownRequested flag and returns. The flag is checked by the worker thread (at worst every few seconds).This all works fine but at present the parent app has no way to determine if the Worker has finished shutting down.I can see a number of ways around this but am not sure what the best one is.Add a State property to IWorker. Should work but I'm going to be polling states which seems a little nasty.Make the shutdown command blocking - Would probably be my ideal solution but I'm not sure how to implement it - does the worker Sunclock a private object which Shutdown() should also try to Synclock after setting the flag?

View 3 Replies

Cannot Access Controls From Worker Thread

Aug 24, 2009

Here is my setup:

Form1.vb - contains RichTextBox1 and BackgroundWorker1, which calls a the Control module.

Control.vb - calls Display module.

Display.vb - calls Form1.SetTextBoxText("text here").[code]...

My observations: When the Display module calls SetTextBoxText, InvokedRequired's is false. Also, if the BackgroundWorker1 (which is in Form1.vb) calls SetTextBoxText, it works. But if BackgroundWorker1 calls a module that calls SetTextBoxText, it doesn't work.

View 4 Replies

Serial Use Of A Background Worker Thread?

Apr 6, 2012

I have a BackgroundWorkerThread which I want to use serially.So some of the code in the UI thread will look like this [code]But of course I can't do the second RunWorkerAsync until the UI thread has seen the RunWorkerCompleted event indicating that the "Sequences" work has been completed (or somehow knows that the "Sequences" work has been completed).So I need some sort of synchronization between the two RunWorkerAsync calls, but whatever I use cannot hang up the UI thread because it has to be able to handle ProgressChanged events.Maybe the RunWorkerCompleted event could make the second call but I really don't like that structure.So how do I delay the second call to RunWorkerAsync (for the "Templates" work) until the background thread has completed the "Sequences" work?

View 6 Replies

Update UI Form From Worker Thread?

Oct 20, 2010

I am new to multi-threading in VB.NET and have come across a problem whereby I am wanting to append text to a text box on a form from a service thread running in the background.

The application I am developing is a client/server listener, I have been able to get the client and server PC's to talk with each other (confirmed through MsgBox), however I am now struggling to get the service thread on the server to append the text to the textbox, nothing vissible occurs.

I have a form named testDebug which calls a class (RemoteSupport), this class does all the handshake tasks and updates the textbox with the connection data.[code]...

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

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

VS 2010 Standard Thread Vs Background Worker?

Apr 25, 2012

I have a application which processes 1000's datas.. for each processing it needs to update gui and db and many variables in my application. So what i have planned is to use 50~90 background worker with my own algorithm of thread pool, synchronization and thread close.So here is it efficient in terms of memory and performance. just confused what to use.. backgroundworker componenet or standard thread.

View 11 Replies

Background Worker - Cross Thread Operation Not Valid

May 30, 2011

I am testing a background workder. I am running the following code for the test.
Private Sub bgwTest_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles bgwTest.DoWork
Dim a As Integer = 0
Do While a < 10 'Infinite loop
ComboBox1.Items.Add(1)
[Code] .....

But this code generates the following error:
"Cross-thread operation not valid: Control 'ComboBox1' accessed from a thread other than the thread it was created on."

View 2 Replies







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