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


ADVERTISEMENT

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

Multithreading - Cross Thread Invoke From Class?

Jan 24, 2012

I am making use of a serial port in a class. I am raising an event from that class to my form calling the class. Event contains data received... I wish to simply populate a textbox from the raised event.Now I am not specifically creating a seperate thread, but I get the normal crossthreading error when trying to update my textbox on the UI, so my assumption is that the serial port and its internal methods probably creates its own threads...Regardless, I am a bit confused as to how to properly implement an invoke, from my main form, pointing to the thread in the instantiated class...

Dim WithEvents tmpRS232 As New clsRS232
Private Sub but_txt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles but_txt.Click
tmpRS232.Set_com_port("COM8", 38400)

[code]....

View 2 Replies

VS 2010 Multithreading Cross-thread Operation Error

Oct 30, 2011

The error occurs at: For i As Integer = 0 To txt_load.Lines.Count - 1..The project exists of 2 rtb's. One with a list of lines. The other will be filled with the converted lines. The main reason that I use it is that I want to use the app during the conversion. The second is that I want to learn how this works.[code]

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

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

Putting A Thread To Sleep?

Aug 22, 2011

Im having a problem with putting a thread to sleep...

othread.sleep(system.threading.timeout.indefinite)

The error is :"Access of shared member, constant member or enum member or nested type through an instance, qualifying expression will not be evaluated"

The code is:

Code:
Imports System.IO
Imports System.Threading
Public Class In_Process

[code].....

View 5 Replies

Code - Putting 0 To 1000 Via Thread In Listbox

Apr 18, 2009

I want to write code that complete task of putting 0 to 1000 via thread in listbox. I want to start 10 threads at startup and complete task.

All threads should work equally. Each thread will write 100 numbers. First start from 0 to 100, second from 100 to 200, third from 200 to 300, so on upto 10th.

I have written code but it has problem.

Dim num As Int16
Dim startLoop As Int16
Dim endLoop As Int16

[CODE]...

View 1 Replies

Multithreading - Thread Getting Interrupted In .NET?

Mar 13, 2012

I am running code in a thread upon opening an Excel workbook that takes some time to execute. If I attempt to close the workbook while the thread is still executing, giving me the standard prompt to Save or cancel, my thread is interrupted (not sure if "interrupted" is technically the right term) when I click Cancel. More generally, it seems that UI interactions/updates cause the thread to be interrupted.

Is there a way to either 1) prevent the thread from being halted by a UI update/user interaction, or 2) allow the thread to resume after being interrupted?Nothing fancy about the code:

Private Shared Sub Test()
Dim t As New Thread(AddressOf DoSomethingThatTakesAWhile)
t.Start()
End Sub

View 1 Replies

Multithreading - Thread Of Execution In .net/COM Dll?

Jun 23, 2012

According to the answers to another question, the VB user interface cannot be updated if the thread that created it is busy: hence why big computational jobs usually have to go in a background task.Here's what's mystifying then. I have the following code. It's called over in-process COM, like this

client calls showform()
client does loads of work, freezing up its own UI in the process
client finishes work, returns to updating its own UI

At step 2, the VB form is there but frozen - you can't interact with it. At step 3, the VB form becomes usable. But why is this? Surely the thread of execution has returned to the client? If the client is somehow handling events for the form, by what magic did it know what events to handle and where to send them?

[Code]...

View 2 Replies

Multithreading - .NET 1.1 Safely Abort Thread?

Feb 10, 2011

I'm trying to safely kill a thread. In my button click I have:

try
dim bar as new foo()
dim mythread as New System.Threading.Thread(AddressOf bar.Start)
mythread.Start()

[code]....

When it goes to abort the thread I still get a thread abort error.

View 1 Replies

Multithreading - .NET Anonymous Function To New Thread?

Apr 29, 2011

I have this code:

Public Sub Submit(
ByVal reasonId As Integer,
ByVal email As String,
ByVal message As String
)
'[Argument validation code here]
EmailController.sendMail(reasonId, email, message)
End Sub

I want to spin this off in a new thread so Submit() returns right after creating and start the thread.In C#, I could do something like this:new Thread(() => { EmailController.sendMail(reasonId, email, message)}).Start();

View 1 Replies

Multithreading - Running A Thread From Within A .net Webservice?

Oct 17, 2010

I have a webservice with a webmethod that accepts an XML from a client via POST (don't know if this really matters), validates XML and the data inside, and then processes the XML and returns an answer to the client.At moment, I have a problem with large XMLs; it takes too long for the XML preprocessing to finish, and the clients timeout expires.

Instead of increasing the timeout of the client I thought I could maybe separate the XML validation from the XML processing by starting a new thread after the validation which processes the XML and at the same time return the validation answer to the client. (the processing won't start if the XML is not valid.

Now my question is: Will opening the new thread increase memory usage? normally I would guess it will (for normal applications) but here I am returning an answer to the client and essentially ending the process of the main thread.

Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.ComponentModel

[code]....

View 1 Replies

Multithreading - Stopping And Restarting A Thread?

Jun 11, 2009

I have an application which has a thread running which makes constant calls to a server. Occasionally, the calls become unresponsive, and I would like to stop and then restart the thread.How do I do this? I can't use mythread.Abort() because then it doesn't allow me to start the thread again.

View 5 Replies

.NET Multithreading / Calling Invoke On A UI Control From A Class In A Separate Class File?

May 13, 2011

Example:

Two files - TestClass.vb, myForm.vb

TestClass.vb looks as follows:

Imports System.Threading
Public Class TestClass
Private myClassThread As New Thread(AddressOf StartMyClassThread)

[code]....

The result:Application runs, no errors or exceptions.Displayed is the listbox and the Start button.I press the start button and a msgbox says "Not Invoked" as expected and upon clicking OK to that msgbox "Start Button Pressed" is added to the Output listbox control.Immediately following that the msgbox pops up again and says "Not Invoked". I was expecting "Invoked" as a separate thread is trying to use the Output listbox control.Of course this results in the Output.Items.Add being attempted which results in no visible result as the thread is not allowed to directly update the UI control.

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

Strongly-typed Generic Method Invokes Its Argument's Base Class Method Instead Of A Shadowed Method In T?

Oct 19, 2010

Consider a MyForm class that contains a shadowed implementation of Show(). It also contains a CreateForm() method, which accepts an instance of the form and calls the shadowed sub:

[Code]....

View 3 Replies

MultiThreading-Insuring A Thread Starts On Each Processor?

Apr 20, 2011

How do I ensure that a process has a thread on each processor?

What I am asking is how do I address processors to ensure a thread is running on it?

View 8 Replies

Multithreading - Modify A Generic Invoke Method To A Generic BeginInvoke Method?

Oct 7, 2010

I have been using a pretty slick generic invoke method for UI updating from background threads. I forget where I copied it from (converted it to VB.NET from C#), but here it is: Public Sub InvokeControl(Of T As Control)(ByVal Control As t, ByVal Action As Action(Of t))

[Code]....

View 1 Replies

Multithreading - .Net: Does Debug.Writeline Stop Thread Execution

Aug 19, 2009

I have a vb.net application that uses threads to asynchronously process some tasks in a "Scheduled Task" (console application).We are limiting this app to run 10 threads at once, like so:

(pseudo-code)

- create a generic list of 10 threads

- spawn off the threadproc for each one

- do a thread.join statement for each thread to wait for the longest running one to complete.

What i am finding is that if the code called by the threadproc contains any "Debug.Writeline" or "Trace.Traceinformation" statements, the thread hangs. I can see the thread in the Debug - Windows - Threads window, and switch to it, but it highlights the debug.writeline statement and never gets past it. is there something special about the Debug or Trace statements that make them non-thread-safe? Any idea why this would hang things up? If I leave the debug statement in, the thread never completes. If I take the debug statement out, the thread completes in less than 5 seconds.

View 3 Replies

Multithreading - Access A Running Background Thread VS2008

Mar 23, 2012

I created a background thread that get's data and returns it to the main thread; this works. Now I want to be able to stop the SQL request from the main thread (probably on a button click). This is my test code for creating the thread (working):

[Code]....

How can I access the background thread to stop the query on demand? Do I need to set a flag on the main thread telling the background thread to stop running then have the background thread poll the main thread at intervals? I was trying to look for an example but I wasn't able to find a good one.

View 1 Replies

Multithreading - How To Ensure That A Code Is Running On Main Thread

Jan 21, 2012

It's easy to do so in objective c but I do not know how to do so in vb.net update:I know about control.invoke. But control.invoke requires a control that may change from program to program. What would be the easier way?So yes program is winform. However I need a solution that does not depend on any specific control. If that's the case actually I do not need things to be run on main thread do I?

View 2 Replies

Multithreading, Events And Cross Thread Data Sharing?

Dec 1, 2011

I am building a code library to be used by a 3rd party developer. Neither my code or the 3rd party have any UI controls involved. It's purpose is a combination of providing the ability to look up information from a database while at the same time polling it and throwing events when a set of conditions are met. Naturally the only way it's going to be responsive to the 3rd party library's commands is via multithreading since everything in a single thread stops once you start polling the database.

The sub I am using is part of an object that I create in the main thread and attempt to have it run via a thread, when a condition is met I have it update a property in that object, throw the event (or execute a callback in my latest attempt) and then attempt to have a simulator for the 3rd party control read the property.It's easy to setup the multithreading part, the hard part appears to be throwing the event so it is seen in the original thread and the data is available there. Any attempt to do this generates a cross thread error when the data is read.

I attempted to use delegates and calling methods asynchronously and using the callback function but still get cross threading errors.Is my only possiblity to use a background worker, using either the progress changed or runworker completed events? Even then am I going to be able to set the property in the function from one thread and read it in another?

View 1 Replies

ProgressBar+MultiThreading Cross Thread Operation Not Valid?

Aug 13, 2011

I'm having difficulty in working with MultiThreading.I want to add to my project a ProgressBar to show the working flow.I'm getting combinations from many Strings, the number of combination can be really big, so it takes few seconds or minutes.

View 6 Replies

Calling Method From Class In VB 2010?

Jul 18, 2012

essentially I need to create a class that houses the methods and then call the methods in the form but I can't seem to find out what the right code is to call it. I think there may be an issue with the conversion from a double to a string.

This is what I have for the Class

Public Class Aircraft
Dim Names() As String = {"A-747", "A-737", "C-150", "D-240"}
Dim TakeOffVelocity() As Double = {250, 264, 270, 240}
Dim Acceleration() As Double = {33.5, 44.2, 37.1, 51.9}

[code]...

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

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 - Copy Method Of Range Class Failed

Sep 18, 2010

Part of my program is to simple copy a range of cells ~21 000 rows from one WB (oSH) and copy it to another WB (oSHOut). I've red a lot of posts,tried a lot of variants, but nothing works. Strange here is that if I copy less than 8500 rows, the paste to the destination range is OK. But if I copy the whole range ~21000 rows, vb.net trigers an error - "Copy method of Range class failed". So I tried to do this in several parts - 1 row to 8000, 8001 to 16000 etc. The first copy-paste works OK, on the secon - there's an error

Imports Microsoft.Office.Interop
Imports System.Data.Odbc
oRNG = Nothing
oRNGOut = Nothing
oSH = Nothing
oSHOut = Nothing
[Code] .....

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

Automated Method Of Getting Disk Space On All Servers And Putting It In A Txt Or Csv (or Even Excel) File Once A Week?

Aug 3, 2011

[code].....

View 10 Replies







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