VS 2010 - Send Variable To Sub On New Thread

Jun 12, 2011

I have created a class with a public sub which has a variable with it using byval:
Public Class clsMessenger
Public Sub Messenger(ByVal Port As Integer)
End Sub
End Class

I now need to start that sub in a new thread and pass a varible to it but I am not entirly sure how to go about that. At the moment I have:
Dim ClientConnection As New clsMessenger
Dim ClientThread As New Threading.Thread(AddressOf ClientConnection.Messenger)
ClientThread.Start()

I can't use a global variable because there is going to be multiple instances of this routine running on different threads and each time the variable to be passed will be different.

View 8 Replies


ADVERTISEMENT

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

Adding Multiple Attachment (files) To A Dynamic Variable So It Can Be Send To A Email. VB 2010

Oct 27, 2010

What to use for adding multiple attachment to a email. I'm using VB 2010.

First, I have a Form in my company web site to fill a reclamation ..... when you fill and send it, it convert the form into a PDF, save it in the client side "TEMP" and finally get the PDF and send it to a email..... that's perfectly fine. I add to the form the capability of attach multiple files with file upload to the same "TEMP" and displayed in a Grid View to remove or add files and send everything to a email, the attachment capability is working. Everything is working with the PDF not the files(attachments).

There is a way to get the multiple files from the "TEMP" folder and add it to some dynamically variable (array list, attachment collection, list collection, etc.) so all can be send to the email. I already know the way to put it into the email with the PDF.

The problem is to get the files and add it to the dynamic variable and that it work with the email. If the code is need it.

View 8 Replies

Send A Notification To Browser From A Thread In Net?

Jan 13, 2012

At the moment, my project has a method

do_quote(quoteid,userid)

This method take a minute or two, and then redirects to another page.

This has been rewritten so that it now runs in the background and redirects to another page whilst the thread which do_quote is on continues. - This works fine.[code]...

What i would like is to send a notification to the browser when do_quote finishes. Ideally i'd like to change the text of a div on the masterpage(but just returning an ALERT javascript msgbox would be a start).

As far as i understand, Callback is called at the end of the process, so i think this would be an ideal place to send javascript to the browser, but i can't think how i could implement this. Does anyone have any ideas on how i could implement a very basic notification (msgbox, response.write etc.) to the browser when the Callback method is called at the end of the process?

View 1 Replies

Get Variable Value From Thread

Feb 1, 2011

I have a thread create by the Threading Namespace.This Thread is doing some work an is waiting in a loop for new information.Now I want to get a value from a public shared variable out of the thread.

View 5 Replies

How To Get A Variable/value Out Of A Thread

May 28, 2010

I want to write some code to do some processing. This seems best done in a thread. But I also want some UI and general controlling passed to and from it. eg: Adding lines to a text box for general UI updating while it's running.Now, let's assume I might have multiple threads running, so each thread can call my UpdateUI subroutine. But the problem is, at the moment my code is using a public variable UI_Msg to pass values back from each thread to the UpdateUI subroutine. This hits me as dangerous as different threads may overwrite UI_Msg at the same time.Instead I tryied to attach a class to each thread, so each thread has its own UI_Msg property/value. When I then get to UpdateUI, I want to pluck this value out of that thread, so there's no risk of different threads overwriting each others msgs to UpdateUI.

Imports System.Threading
Public Class MainForm
Public UI_msg As String

[code].....

View 7 Replies

How To Return Variable From Thread

Mar 10, 2009

This is my simple code that calls a function from a class I created called "clsNetwork". The function simply pings a computer from a computername I pass it and returns the results.

Dim PingStatus As String
PingStatus = clsNetwork.PingComputer(ComputerName)
txtbox.text = PingStatus

View 13 Replies

Syntax For Control.Inoke To Send Integer Array From Backgroundthread To UI Thread?

Jun 24, 2010

with the code below, I'm trying to send an integer array from a background thread to the Main Form which contains a User Draw Control. I currently get the error:"Invoke or BeginInvoke cannot be called on a control until the window handle has been created."

Public Class Form1 Me.TabPage.Controls.Add(Me.DrawGraph) 'designer.vb
Public InjectIntegerArrayDelegate As InjectIntegerArray
Delegate Sub InjectIntegerArray(intarray As Integer())
InjectIntegerArrayDelegate = New InjectIntegerArray(AddressOf InjectIntegerArrayMethod)
public Sub InjectIntegerArrayMethod(SensorData As Integer())
DrawGraph.Int_Clutter_In = SensorData

[Code]...

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

How To Send Variable Arrays Via Network

Mar 7, 2009

I am really new to .net, I've got the basics to a game down, I need to be able to send variable arrays between programs, I am aiming for local network first, then I'll tackle internet. Does .net have any simple way of doing this? Was difficult in vb 6. It needs to be fast so both machines get the same view of the game.

View 5 Replies

Send A Variable From Form1 To Form2?

Jul 28, 2009

I have looked around and I can not find what I am looking for. I would like to send a variable from Form1 to Form2. I have found out how to send I text box from form1 to form2

How can I send a var from From1 to From2?

View 2 Replies

VS 2008 How To Send Time To A Variable

Jul 2, 2011

Im trying to get hour to a variabel, and also minute to a variabel.I have build this code but it dosen't work.

dtCurrent = dtCurrent.Now()
tdCurrent = tdCurrent.Now()
iMin = tdCurrent.Minutee function does not work.

[code].....

View 5 Replies

Commented Code Won't Work - Time The Thread Start, The Variable CurrentFarm Have Changed.

Mar 1, 2011

Vb.net For each currentFarm in ......

If urlQueue.Count > 0 Then
Debug.Assert(currentFarm.isBusy = False)
Debug.Assert(currentFarm.WebClient.IsBusy = False)

[CODE]...

The commented code won't work. That's because by the time the thread start, the variable currentFarm have changed. So I create a new function and cache the currentFarm in the function parameter. No there will be a cache of currentFarm address (object is always a pointer) on a stack and that address is the one being passed to the System.Threading.Thread constructor.

View 5 Replies

VS 2010 Compiler Creates New Variable Automatically When Use If Statement Without Strictly Declared Variable?

Jan 10, 2011

Say that i have the following code that parse about 20k records from the DB.

Code #1

vb.net While reader.Read()
list.Add(If(Integer.TryParse(reader(0).ToString, 0), Integer.Parse(reader(0).ToString), 0))
End While

And then another code which does the very same thing but it seems to be a little cleaner.

Code #2

vb.net While reader.Read()
Dim storeowner As Integer = 0
Integer.TryParse(reader(0).ToString, storeowner)
list.Add(storeowner)
End While

This is what i am confused about; does the compiler creates a new variable automatically when i use the if statement without strictly declared variable? What approach is better in sense of performance?

View 2 Replies

VS 2010 Merging An Integer Variable With A String Variable?

Jun 2, 2011

Say I have something like this

Dim Level1 as Integer = 83
Dim Goal as String
Goal = InputBox(" What level is your goal?")

[code].....

View 7 Replies

Send Multiple Email From Contacts With Variable In Message Body?

Feb 18, 2010

We have an excel spreadsheet with about 10000 names (company and email address) and we need to send some legal docs to them. I'm looking for a way to automate this either via a macro in excel or templates in outlook.Problem with macro in excel is that the code I was able to findcustomize doesn't let me insert a formatted text in the message body.[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

Use Thread In 2010?

Jul 26, 2011

i want to use thread in vb.net 2010 and have problem :( after run the project showed this message for meError > " Controls created on one thread cannot be parented to a control on a different thread."

Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

[code].....

View 7 Replies

VS 2010 - Too Much For The UI Thread To Handle

Jan 22, 2011

I've got a form that acts as a progress report for a long running operation, it has a listview on it (which I might be replacing with a DGV soon) that gets updated with progress updates from a background thread that is doing all the work. The method running on the background thread raises events that the form then handles and adds the string passed in to this event to the listview. The method running on the background thread raises progress update events several times a second and for each of these updates the event handler on the form must invoke a method on the UI thread to actually add the item to the listview.

This works fine on my test PC (which has a quad core CPU and 8 GB of RAM) but others have reported that after a while the form goes to the Not Responding state so I'm assuming all of these updates on the UI thread are being requested too often for it to be able to process them all as well as user input.So I'm looking for a better solution and have come up with the following:When the background thread raises these progress updated events, instead of them being added to the listview instantly I add them to a Queue(Of String). Then every second the form would check this queue and remove any items currently in it and add them to the listview - using a Queue(Of T) instead of a List(Of T) should guarantee they come out in the correct order. Both of these operations (adding to the queue and reading/removing from it) would be done under a SyncLock block that would lock on the same object to avoid both threads trying to work with the queue at the same time, so there would still be some contention but I'm hoping it would mean the UI thread only gets busy once a second instead of potentially roughly 30 times a second as it is doing now.Does that sound like a good plan? Can anyone think of a better way of handling this?

View 18 Replies

VS 2010 C++ Dll Is Not Thread Safe?

Apr 19, 2012

I'm calling a c++ dll I made myself - and it appears to be very VERY not thread safe!

I'm referencing it like this

<System.Runtime.InteropServices.DllImport("D:ACS DesktopdcxdcxDebugStringLibrary.dll", EntryPoint:="firstIndexOfKeyword", CallingConvention:=Runtime.InteropServices.CallingConvention.Cdecl)> _
Public Shared Function firstIndexOfKeyword(ByVal s As String, ByVal substr As String(), ByVal substrLength As Integer, ByVal markers As Integer()) As Integer End Function

Is there a way to make this IMPORT create something more threadsafe?

[Code]...

View 10 Replies

VS 2010 How To Multi-thread

Feb 8, 2011

How do i go about multi-threading that, it's just an example project, so i can try and learn from it. As i'm having a hard time understanding JMC's tutorial as it doesn't directly relate to what i'm trying to do [code]When you hit 'Start', the start button is disabled and the Label1 then changes to "Downloading".The data is then downloaded and put into the Textbox1.Label then reads "Complete" Start button is enabled.

View 5 Replies







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