Canceling A ThreadPool Thread That's Being Blocked By A .NET Method?

Aug 14, 2009

I have a task that needs to be executed many times in a thread, so as to keep my GUI responsive. Right now I'm using the ThreadPool to accomplish the tasks, and it works perfectly. I get all the data I expect back from the threads, life's good. When those tasks are finished, I then fire off another set of threads to accomplish another set of tasks, in the same fashion. The work method of these threads uses a call to RegistryKey.OpenRemoteBaseKey, which does exactly that, opens a remote registry key. The problem is: if the user running the application does not have permission to open the remote registry the call will throw an IOException, but I expect this behaviour because the user does not have permission to do it. However, the call itself can take FOREVER.

I wrote the application initially to use delegate methods and used the WaitHandle.WaitOne() method on AutoResetEvents in a state object I passed to each delegate. I tried the WaitOne method using a timeout, which worked fine until I realized that even though the WaitOne timed out, the thread was still running. This is a problem because (from what I understand) processes are only given a certain number of ThreadPool threads and, once used, they must be finished in order to be released back to the threadpool. In my work method, I also have a variable that can be signalled when the thread should be stopped, but that (obviously) only works on code that I've written.how can I cancel a thread that's stuck on a .NET method? Is there some sort of garbage collection method I can call if I give it a handle?

View 18 Replies


ADVERTISEMENT

VS 2008 2 Threadpool - One Threadpool For Scanning Files And Second Threadpool For Moving File's Into Drive's

Jun 4, 2011

I m trying to move all my drive's files into h drive firstly i have added all drives in threadpool for scanning and when scanning of any drive finish (Without waiting for other drive's complete ) it will move file's to h drive but it is not working as i wanted that's why i need two threadpool - one threadpool for scanning files and second threadpool for moving file's into drive's

View 11 Replies

Canceling The Previous Thread?

Dec 10, 2009

I have a program in VB2008 and I need to execute a thread from differents Subs.Each time I start the thread I want to cancel the previous.Here an example:

Private Sub TextBox_Changed(ByVal sender As System.Object, ByVal e As System.EventArgs) Dim ThreadResults As New Thread(AddressOf ShowResults) ThreadResults.Start() End Sub Private Sub ckBoxAllRecords_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Dim ThreadResults As New Thread(AddressOf ShowResults) ThreadResults.Start() End Sub

I write in a textbox, TextBox_Changed fires, thread spend 4 minutes filling a dataset I check a checkbox, ckBoxAllRecords_CheckedChanged fires, thread spend 10 seconds filling a dataset.I dont want anymore the dataset of TextBox_Changed so I want to cancel its filling.

View 2 Replies

Incompatible Signatures When Spawning Thread With ThreadPool?

May 5, 2009

The error is:

Method 'Private Sub ProcessToolWork()'
does not have a signature compatible
with delegate 'Delegate Sub

[code].....

View 2 Replies

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

C# - Reassign Thread To A Different Method .net?

Feb 16, 2010

Is it possible to reassign thread to a different method, once it has been instantiated. If not, are there alternatives?

View 2 Replies

Call A Method In A Thread?

Dec 29, 2009

I have a class that runs as a thread. While the thread is running, I want to call a method in that thread. I do this commonly where a thread calls a method in the GUI with a delegate. But I'm confused how to do this when the called thread is not the GUI and there are no parameters passed to the called method.

View 8 Replies

VS 2010 Run Method On Non-UI Thread?

Dec 11, 2011

Usually I use the synchronizationcontext to run methods on my GUI thread from a background thread. But now I need to do it the other way around and the synchronizationcontext class doesn't work on threads that don't have a GUI. What I basically need to do is, if there is anything going on on the thread I want to run my method on, I want to pause or interrupt it and run my method and then let it continue.

View 4 Replies

.net - Is The Enqueue Method Thread Safe

Nov 2, 2009

Let's say that I have a module that has a Queue in it. For other entities to Enqueue, they must go through a function:

[Code]....

If I have multiple threads running and they want to call InsertIntoQueue(), is this considered thread safe? I am under the impression that there is only one copy of the instructions in memory necessary to perform the InsertIntoQueue() function... which would lead me to think that this is thread safe. However, I wonder what happens when two threads attempt to run the function at the same time? Is this thread safe, and if not, how can I make it thread safe? (and What would be the performance implications regarding speed and memory usage)

View 6 Replies

Call A Method Which Has Two Parameters Using Thread?

Jun 8, 2009

I am trying to call a method which has two parameters using thread. How can I do this? If I pass parameter to my thread.start() method, it is giving error.

View 1 Replies

Create A Thread And Associate It To The Run Method?

Feb 8, 2010

I'm trying to change/execute the example [URL]...onContext.aspx I've posted my project below. I'm getting a cross-threading error and I thought the point of all of this was to avoid that. (yes I realize I could just delegate... I'm trying to do something more complicated but am using this as a test bed)

[Code]...

View 17 Replies

Cross-Thread Method Access?

Jan 29, 2009

I've got a problem. I'm running a different thread. The thread's sub is looping, doing various things during the program, and eventually tries to close the form. I get an error, because the other thread can't access the "Me" object, I guess. It won't close the form. I don't want to use Application.Exit. Is there another way?

View 3 Replies

.net Thread Safe Method To Add A Listview Subitem?

Feb 21, 2011

I am trying to add a subitem to a listview in a threadsafe manner.In a single threaded application it works like so:

[Code]...

However if run in another thread it causes a cross threading error.I have looked at examples of delegate subs that use Invoke, but all examples i have seen involve updating the text property of an object, and i cant get my head round how to apply the concept to actually add a subitem to a listview.

View 3 Replies

C# - Interacting With The UI Thread From An Async Callback Method?

Nov 15, 2009

I have a method that is asynchronously called when System.Net.Sockets.NetworkStream.BeginRead completes.

skDelegate = New AsyncCallback(AddressOf skDataReceived)
skStream.BeginRead(skBuffer, 0, 100000, skDelegate, New Object)

In that callback method, I need to interact with the UI thread.

Sub skDataReceived(ByVal result As IAsyncResult)
CType(My.Application.OpenForms.Item("frmMain"), frmMain).refreshStats(d1, d2)
End Sub

This causes an exception after the method completes. (when End Sub is executed)

[Code]...

View 4 Replies

VS 2008 Passing A Class Method In A New Thread

May 14, 2010

I am looking for a way to pass a class method into a new thread. On my form I have a few object that contain methods.

For example obj1.doWork.

Now I want to do

Example
Dim t as new Thread
t = new Thread(AddressOf obj1.doWork)
t.start()

However I get an error on this saying:

Error1Overload resolution failed because no accessible 'New' is most specific for these arguments:
'Public Sub New(start As System.Threading.ParameterizedThreadStart)': Not most specific.
'Public Sub New(start As System.Threading.ThreadStart)': Not most specific.

View 11 Replies

Put Method In Main Thread From Background Without Declaring Delegates?

Nov 23, 2009

put method in main thread from background without declaring delegates

View 2 Replies

Thread Safe Method Invoke Doesnt Work?

Jan 2, 2010

I Have a Function on my frmMain Class wich will update my control to something else after an invoke. When i type "?Label1.Text" on the Immediate Window, the text property IS updated, but when i go check the Form, nothing happened. The code is just like this

[Code]...

View 3 Replies

VS 2010 Multithreading, Putting Class Method On New Thread?

Jun 4, 2011

Right now I have a Email class that has all the properties of an email to send it, and then a SendEmail function which takes those properties and uses them in the following

Public Function SendEmail()
'Exception handling
Try

[Code]....

The loop goes through each email in the array to process its email, however with the multithreaded function I cannot call

"EmailArray(i).ThreadSendBatchEmail()"

So how do I call an objects method when its on a different thread?

And I'm making it multithreaded so I can easily pause the process, and because the program freezes when the send() function is working, this would resolve that.

View 17 Replies

VS 2008 POP Up Blocked?

Jul 31, 2010

For Some Reason My Pop Up Blocker wont workbut if i debug the application it will work for some reason pleaerror code below:

************** Exception Text **************
System.InvalidCastException: Unable to cast object of type 'System.Windows.Forms.MouseEventArgs' to type 'System.ComponentModel.CancelEventArgs'.

[code]....

View 4 Replies

XML File Blocked?

Dec 18, 2010

I have a script which calls a XML file such as this,

Dim textReader As XmlTextReader = New XmlTextReader(Domain & "scripts/newsxml.php?LastUpdate=" & MyLastUpdate)
Domain is
http://192.168.1.4:8081/[code]....

Localhost host works fine when running it off my machine,when i run it off my laptop under the local IP 192 i get a error saying it was activily refused, when i load http:[url].... it loads my webpage fine.

View 1 Replies

Callback Method - Cross Thread Operation Not Valid Exception?

Jul 28, 2009

I have a windows form that gets data from a scale via the serial port. Since I need the operator to be able to cancel the process I do the get data process on a second thread. The data collection process gets multiple readings from the scale one at a time. The form has a label that needs to be updated with information specific to each reading.

I call the method to get the data from the scale with this code.
Dim ad As New readALine(AddressOf thisScale.readALine)
Dim ac As New AsyncCallback(AddressOf Me.GetDataCallback)
Dim iar As IAsyncResult = ad.BeginInvoke("", ac, ad)

The delegate for the readALine method is defined in the UI code.
Delegate Function readALine(ByVal toSend As String) As String

The GetDataCallback method:
Private Sub GetDataCallback(ByVal ia As IAsyncResult)
.
.
.
lblInstructions.Text = _thisMeasure.dt.Rows(_currRow - 1).Item("cnt") & ":"
lblInstructions.Refresh()
.
.
.
End Sub

I get the exception on the "lblInstructions.Text =" statement. I thought the GetDataCallback method was part of the UI thread so don't understand why I'm getting the exception. I know this could probably be rewritten using a BackgroundWorker and it's appropriate events but for now would like to understand why this isn't working as expected. The application was written originally in VS2003 and just recently upgraded to VS2008.

View 5 Replies

Multithreading - .net Avoiding Cross Thread Exception With Extension Method?

Jan 13, 2011

I am trying to implement a solution for updating form controls without using a delegate.

Imports System.ComponentModel
Imports System.Runtime.CompilerServices
Public Module MyInvoke

[code]....

I get a cross threading error as though i didnt even use this method:Cross-thread operation not valid: Control 'ComboBox1' accessed from a thread other than the thread it was created on.

View 3 Replies

Popup Blocked By Project Browser

Jul 8, 2010

What I'm working on now is a web browser. Here is what I've got for the code so far. Its Really simple.
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Text = "Web Browser"
[Code] .....
BTW this is VB 2008 I don't know if 2010 is any different codding than 2008.

View 3 Replies

VS 2008 Visit Blocked Websites?

Mar 8, 2011

i was wondering if there is any way to visit a blocked website using visual basic 2008. i want to use during school in programing class.. just to let you know my teacher said he will let us get by with it, if we could even make something like this.

View 8 Replies

Canceling A While Loop Prematurely

Aug 17, 2009

I'm using a While loop that loops a certain number of cycles (1-576) based on a value entered by a user. It's activated by the user clicking a "Start" button, But I would like it to be able to be canceled using, preferably, the "Escape" key. However, when the loop is going I can't get the program to recognize any keypresses.

[Code]...

View 4 Replies

Check If Port Is Blocked By Windows Firewall?

Aug 15, 2011

How do i check if specific port is blocked by Windows firewall , both in incoming and outgoing connections.

I've seen code samples such as this one:

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim host As String = "localhost"
Dim port As Integer = 6900

[Code]....

But how can i know if the exception is thrown specifically because of firewall blocking, and not because of other socket errors?

View 1 Replies

Wrong Input For 3 Times And Account Will Be Blocked?

Mar 22, 2012

I am making a banking system in Vb.Net but I had a problem with this function. If a user fails to input the pin number for 3 times, it will be block automatically and will need the admins permission in order for that person to activate the account again. I really don't know how to code the blocking of account and asks for admins authorization to unblock the account again. By the way I'm also using MsAccess as my database for my Bank Simulation.

View 5 Replies

BackgroundWorker.CancelASync() NOT Canceling Bg Worker?

May 13, 2010

I've set up a background worker to search a directory for emails and if my specifi criteria (i.e. date ranges, contains a word) are fulfilled, then a list view is populated.I have this working absolutely fine - when I click search, the list view is populated as I watch - but when I press my 'Stop' button, which runs bg.CancelASync() it does not stop the process at all - results still populate in the list view as it was before.

View 1 Replies

Canceling Data Input In Datagridview?

Mar 4, 2010

I have a DataGridView in which I register customer orders.

The DGV has a column "PRICE", Price must be > than 100, and I control that in this way:

Private Sub DataGridView1_CellValidating(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellValidatingEventArgs) Handles DataGridView1.CellValidating
Dim newInteger As Integer

[Code].....

View 2 Replies







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