Call A Delegate From Separate Thread?

Jun 10, 2011

So, I'm having troubles implementing a separate thread. This is because I have a simple class, and in it I start a new thread. So, as it is not any form, I haven't found any way to make it call the function in the UI Thread.

So, I cannot use the Invoke method. Is there any way to call a function from another thread?

View 2 Replies


ADVERTISEMENT

Call A Method That Started On A Background Thread On The UI Thread Calling BeginInvoke And Passing In A Delegate?

Aug 27, 2011

I am trying to call a method that started on a background thread on the UI thread calling BeginInvoke and passing in a delegate as follows:

Dispatcher.BeginInvoke(Function() UpdateApplicationDataUI())

to call this method:

Private Sub UpdateApplicationDataUI()
...
End Sub

However, I get an error in the call to BeginInvoke (the UpdateApplicationDataUI portion of the delegate is stating "Expression does not produce a value").

Me.Dispatcher.BeginInvoke(Function() New Action(AddressOf UpdateApplicationDataUI))

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

Multi-threading Forms - Open A Separate Form As A Separate UI Thread From The Start Up Form

Oct 27, 2011

I have a few forms that have a lot of really intensive updating along with a great deal of user interface (text boxes, button clicking etc) Is it possible to open a separate form as a separate UI thread from the start up form that called it to "show" or open or whatever the new method might be?

View 6 Replies

Executing Delegate In Existing Thread?

Aug 5, 2009

I have a GUI which executes on the GUI-thread. Further I have another thrad which does video processing using DirectShow (this is COM).

- Now I want to execute a function on the same thread as where the videoprocessing is executing. This is initiated by the GUI-thread. Touching the COM-referenced object goes wrong if a execute the function from another thread (I understand that). When a call the function from the same thread everything goes fine. But to do this I have the poll some flag-bits in the mainloop, and that is not a 'pretty' solution...

All discussions on the internet are about how change the GUI from a different thread.

I have tried several things:

1) Invoke the function using a delegate. This doesn't wordt, since the function is executed in the GUI thread. (checked bu ThreadID's)

2) BeginInvoke the function using a delegate. May be .net executes the function in a original thread where the object has been created. This does also not work: .net used random threads (probaby from the threadpool)

3) ISynchronizeInvoke, Threading.SynchronizationContext and some other features seems only to work on the GUI thread only...

The question: Is there a way to Post, Send of Invoke a delegate on the specific thread (for example by a reference to this thread or threadID)

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

Thread Do Not Resume When The Delegate Returns?

Jun 2, 2010

It seems that there is a glitch in Vb, While having some tasks ( Thread ) queued using Tasks if you try to use Invoke, the thread do not resume when the delegate returns.If BeginInvoke is used, it works but the problem is that it become impossible to execute a delegate synchronously.This does force the use of the AutoResetEvent to control the thread.The problem comes when the thread execute some code in a other classes, using a single AutoResetEvent within many classes just give a very dirty code.

View 1 Replies

C# - Abort A Thread Started With Delegate.BeginInvoke?

Feb 1, 2010

Disclaimer: I know that Thread.Abort is evil. I'm using it as a last resort since some I/O functions (e.g., File.Exists when used on a non-existing network share) block for a large amout of time and do not allow you to specify a timeout.

Question: Is it possible to Abort (as in Thread.Abort) a worker thread started using Delegate.BeginInvoke or do I have to do the Thread handling myself?

View 2 Replies

Invoke Parameterized Function Delegate From Background To UI Thread?

Oct 4, 2010

What is the Invoke syntax to marshall data from a background thread receive callback method to a function on the UI Thread?(Form1).

Public Class Form1
MyDelegate = New DisplayData(AddressOf DisplayData)
Private Sub Form1_Load()
MyDelegate = New DisplayData(AddressOf DisplayData)

[code]....

View 12 Replies

How To Define Delegate For TextBox1 And Call Invoke

Feb 3, 2009

I have a few textbox for data display and RS232 communication in my application. After I send characters on RS232, I want text boxes display feedback characters from RS232 receive. So in SerialPort_DataReceived() i was told to use Invoke to display received characters on TextBox1, TexBox2.how to define delegate for TextBox1 and call Invoke()?

View 9 Replies

.net - Call Winforms-style Invoke/Delegate From MVVM?

Oct 12, 2010

I'm hacking away at some code which seems to have been started, at least in theory, as an MVVM project in Expression Blend, by my predecessor at this company.

I've got a thread running in the background, which is running some operations on items as they happen. In order to prevent any clashes, I've also got that thread running any operations my users call for.

Once those operations are completed, I'd like to bring up a MessageBox to give a summary of the user-initiated operations, but now that they're running off in their own thread, the finishedProcessing event handler is now running on the background thread instead of the interface thread and it's causing my MessageBoxes to appear non-modally.

Back in the WinForms days, I'd have handled that using InvokeRequired, Invoke and a Delegate. I've read that this has been replaced by something called "Dispatcher", but the ViewModel class I'm using doesn't seem to have a Dispatcher object.

The "thisViewModel" class I'm using inherits a class called "WorkspaceViewModel", which inherits "ViewModelBase", both of which look generated to me...

where I can link up to this "Dispatcher" from here?

View 1 Replies

Run A Loop In A Separate Thread?

Sep 24, 2010

Is there a way I can run a loop in a seperate thread and increment a progress bar each time the loop iterates? I am trying to run a loop that will take a long time to complete and I dont want the form to be completely crashed out while the loop is running. There are only two ways I can think to solve the problem. The first way is to run the loop on a timer. This is extremely slow. The other way is to use a thread.

View 1 Replies

Run Timer On Separate Thread

Jun 2, 2012

I just finished up my space invaders movement and with all the other timers running it really bogs it down. So I think the best solution would be to make the timers run on separate threads. I know roughly how to do this from a old example I read a long time ago. So I just need a simple sample code to refresh my memory please. Maybe something with message boxes or something to demonstrate the process.

View 1 Replies

List.ForEach(Delegate) Call ReadAndPopulate Method For Each Item In AList

Jun 29, 2011

Here's the code I have but I'm getting syntax issues:

CODE:

I'm just looking to call ReadAndPopulate method for each item in aList. I know I can do it the traditional "For each a in aList...Next" way but wanted to learn how to do it with delegates.

View 8 Replies

Pass Multiple Arguments To A Delegate Method From A List(Of T).ForEach Call?

Sep 6, 2011

Is it possible to pass multiple arguments to a delegate method from a list(Of T).ForEach call?So, I'd like to pass a listbox object to the delegate routine below:

Sub test()
Dim names As New List(Of String)
names.Add("Bruce")
names.Add("Alfred")

[code]....

View 4 Replies

Allow A Progressbar To Be Changed On A Separate Thread?

Mar 6, 2011

how can i allow a progressbar to be changed on a seperate thread? my code keeps saying that i cannot access it because it was created on a seperate thread:

[Code]...

If it is not worth it, it is not fun - you say programmers are boring but i say they are worth it.

View 1 Replies

Create New Form On Separate Thread?

Jan 10, 2010

I would like my application to do something (in one form) and while form is doing that i would like to show another form to the user. Code is:

Private Sub blaa()
Dim a As New Working() 'working is another form
a.Show()
'Do some stuff
a.Close()
End Sub

But when i make new form i find it is on the same (main thread) and therefore new form also frozes. How to make new form on separate thread?

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

Running Function In A Separate Thread

Mar 31, 2011

when trying to run a function in a separate thread, my reason for trying this is because since the application is only run on one thread, the GUI hangs when the function is called.[code]In this code, the Print screen Button is pressed and the function HookCallBack is called.The problem is that the function has variables that need to be passed and returned, and while searching, i found a website that had an answer for this, and it required the function to be put in a class, and then it could be run on a separate thread while still passing all the variables needed.url...But the code cannot be placed in a class without giving errors and it seems to me like i did something wrong. The code is meant to be used in a form and not a class.My question is, how would i go about running the HookCallBack Function in a Separate thread?

View 5 Replies

Running Process In Separate Thread

Mar 24, 2009

Here's the problem I am trying to solve. My program can export a file as a pdf. and other formats. I can open the file using process.start. My file doesnt have a good name so I am using a GUID as a name.

[Code]...

View 2 Replies

UI Freezes Though I'm Running My Sub On A Separate Thread

Aug 11, 2011

I'm working on a checksum tool, which loads all the files in a specific folder to a listview then, calculates the hash value of each file and save it to a text file.Ok, everything is working properly except for the calculation, when I start it on a separate the my UI freezes.[code]...

View 5 Replies

Update A Form From A Separate Thread?

May 9, 2010

I've looked at the on line doc over and over, and I can't seem to figure out why this won't work. This code runs the thread, and the thread seems to execute the code in the 'threadsafe' sub, however neither the progress bar is updated or the button click performed.

Imports System.Threading
Public Class VisNotify
Inherits Form

[Code].....

View 4 Replies

Update UI From A Class In A Separate Thread?

May 4, 2010

The code below works fine when I put it in form1.vb and change "form1" to "me" but I can't seem go get it to work from my class.

VB
Imports System.Threading
Public Class Class1

[Code].....

View 2 Replies

Adding Items To ListView In Separate Thread?

Jan 26, 2010

For some reason, the following code is causing me some issues. This code pulls lockout status data from AD and contains the data within a datatable. An event is raised from the threaded procedure to add the data to a listview control. For some reason one row of data gets added to the listview control and when you run the procedure gain, 2 rows of the same data gets added, and then 3 rows, etc.

This code calls the procedure "CallGetUserLockout"
GetLockoutStatusToolStripMenuItem.DropDownItems.Add("For Current User - " & User, Nothing, AddressOf CallGetUserLockout)

[code].....

View 3 Replies

Create A Timer To Execute On A Separate Thread?

Jan 23, 2012

Currently I'm creating a task that runs a hardware i/o loop for the duration of my program.i.e. it's a task that's created at the program's start and runs a loop that is only broken at the programs termination. Each loop cycle communicates via ethernet to hardware.depending on time outs each cycle takes 30-300 msec)I've noticed that if the loop runs with out any break that the program really slows down... to counter act that I placed a thread.sleep(x) in the loop

View 6 Replies

Forms :: Load Progress Bar On Separate Thread?

Apr 29, 2010

I have created a form in which i am loading thousand of records. so i want to display a progress bar.Actually i am moving from MDI main meny to some other form so when i click that menu item i want to progress bar till my total records are not loaded.

View 3 Replies

How To Set Global Keyboard Hook On Separate Thread

Apr 29, 2012

After many searches i end up using this class for global keyboard hooking. Link: Global Hook post [code]My app is performing operations that take some seconds to complete (ftp upload small files on interval), and during this time the hook lovks the keyboard. This i dont want of course..I cant jump to Async FtpWebRequest right now because it needs many changes, so i thought that the solution would be to make the hoook live in another thread.A proposal is to move my time - consuming operations (upload) to another thread.Upon doing this i am facing other problems. Because the time consuming task (upload) is in a timer i would have to rewrite a big portion in order to synchronize the file->save with the file->upload and i dont mind the app locking for 3-4 secs. what i do mind is to loose the kayboard for 3-4 secs.

View 2 Replies

Plot Serial Data In Separate Thread?

Dec 29, 2011

my application receive data from serial port and store it in ConcurrentQuequeFor not lost any data from serial port I need to plot it in a separate theadin SummaryForm Load = set all parameter of ZedGraphPulsante Start = Open serial Port and start Thead

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

VS 2008 Infinite Loop In Separate Thread?

Jun 25, 2010

Im working with and trying to run an infinite loop on a new thread which at some point takes action (e.g. make changes to Viewport3D). But no matter what I use:

- BeginInvoke

- Background Worker

- Timer

I run into problems. My porblems are:

[Code]....

I am doing all this in WPF.

How can I run the loop in the background and get it to affect the Viewport3D controls content without throwing an error or freezing up the application? A Viewpoirt3D is a control in WPF.

View 5 Replies







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