Threading Class FrmMain To A Module And Modifying UI Thread Values?

Jan 15, 2010

In frmMain:

Private Sub DBReadAccountInfo(ByVal strAccountID As String)
Dim tmpaccountInfo As New PublicFunctions.clsAccountInfo
tmpAccountInfo.strAccountID = strAccountID
Dim ReadAccountInfo_Thread As New Thread(AddressOf tmpAccountInfo.DBLookupAccount)
ReadAccountInfo_Thread.IsBackground = True

[code]....

In "sub UpdateAccount", frmMain.InvokeRequired is always false. There's a MenuStrip control I'd like to update the .Text on.

View 6 Replies


ADVERTISEMENT

Exception W/ Threading And Invoke In A Class - Read A Sock Without Freezing The Thread?

Mar 12, 2011

I have created a class for Socket reads so I can create sockets on command. Due to performing a socket read, the program will freeze waiting for incoming data due to being on a single thread. So I created a separate thread for the reading of the sock and attempt to invoke an event to prevent multi-threading errors.

But I am getting an error when trying to Invoke: "Invoke or BeginInvoke cannot be called on a control until the window handle has been created."

How can I fix this or is there a better way to read a sock without freezing the thread?

Class for Sockets:

Option Explicit On
Option Strict On

Imports System.Text

[CODE]...

Calling form code example:

Private WithEvents Socks As clsSock

Private Sub Sock_Connected(ByVal state As String) Handles Socks.Connected
MsgBox("Connected - " & state)

[CODE]...

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

VS 2008 Terminate A Threading.thread Using Thread.abort?

Jun 10, 2010

im trying to terminate a threading.thread using thread.abort the thread runs a download connection so is usually in the middle of socket.recieve or socket.send or socket.connect when aborting i just want to terminate the thread no matter what thread.abort raises an MDA excpetion. so i ticked it off in the debug exceptions menu. now it doesnt raise an exception, but the thread simply wont terminate. my program wont close unless i press top in the debugger.i cant pause downloads because i cant terminate the thread this code wasn't working?

Dim vT As Threading.Thread
For Each vT In clsDownloader.DownloadThreads
If Not vT Is Nothing Then
vT.Abort()

[code].....

as for the exception concerning threads being aborted from other threads being dangerous, how is it possible to send a message from a main thread to another thread to abort itself? as far as i know the only way to a abort one thread from another is to just kill it (because i dont know of ways for a thread to communicate with another).

View 2 Replies

Declare Main Class On FrmMain - Working With Classes?

Jun 3, 2009

Currently I declare my main class on frmMain. as public MyClass as new clsMyClass Thus anywhere in the application I would address it as: frmMain.MyClass.Function(MyParam) This does not look as neat as I would like it. Where can I load this Class so that I can address it as: MyClass.Function(MyParam) from anywhere inside the application.

View 6 Replies

VS 2010 Modifying A Collection Currently In Use On A Different Thread?

May 17, 2011

So one of my programs logged an error the other day that I am trying to fix. The error was Collection was modified; enumeration operation may not execute.To overly simplify my code, users can add or delete objects from the collection at runtime. In the background, on a separate thread, a process runs every so many seconds that syncs the data in the collection with the data in a flat file.

To avoid my problem, it seems the most logical to create a COPY of the collection at the start of my second thread's procedure, and run off of that.How do I do that?If I try to say something like.

[Code]...

View 4 Replies

Ide - Ctrl-Break Suspends Code On "Partial Class FrmMain"?

Feb 1, 2012

This is an IDE question for VB Express 2008. It might be a bug in the IDE, or maybe it's my fault somehow?

My main form is named FrmMain and in my application's properties I have set frmMain as my startup object. All of that seems like what a lot of coders do.

But while debugging I hit Ctrl-Break, as I have done for years, and I get an behavior in the IDE that I wasn't expecting. Upon doing so, I get the green background text and the green arrow indicating in a tooltip: "This is the next statement to execute when this thread returns from the current function." Even if I didn't have the designer document open, it automatically opens frmMain.Designer.vb in the editor and hihglights line in green. The line is of course: Partial Class frmMain which is line 2 of the file. (Yes, it's highlighting the second line of the designer-generated code.)

The thing is, frmMain seems to have fully loaded and it's my startup object. As far as I know there shouldn't be a "next statement to execute" at all because code should be idle. I don't want to see the Designer.vb document... I want to edit my own code. Even though my form is behaving just fine, could there somehow be an unfinished aspect of loading the form such that it is "not returning" from a function?

Edit: In response to a couple comments, I'm adding three screen shots:

View 3 Replies

VS 2010 Multi Threading Access To Module Level SEQUENTIAL Counter?

Feb 22, 2012

I've got this code

Public Class Form1
Dim m_listener As HttpListener = Nothing
Dim m_asyncCount As Integer = 0

[code].....

View 8 Replies

.Net System.Threading.Thread.Sleep(X) Application?

May 13, 2012

I have this little application that is using a System.Threading.Thread.Sleep, application runs great but Windows thinks the application is not responding even though it is running.

[Code]...

View 14 Replies

C# - Difference Between BackgroundWorker And System.Threading.Thread

Oct 24, 2009

What is the difference between creating a thead using BackgroundWorker and creating a thread using System.Threading.Thread?

View 2 Replies

Threading.thread Addressof Passing Variables

Apr 16, 2012

I am trying to pass some status from a IP call in a shared sub to a label on my form. This is the current code that i am using:

[Code]....

View 1 Replies

VS 2008 : Threading.Thread.Sleep Won't Work

Mar 13, 2010

i got inside

WebBrowser1_DocumentCompleted sub

the code below

WebBrowser1.Document.GetElementById("form").InvokeMember("click")
Call ProcessNextLine()

when it clicks this button it should load another page(Like log in)

Call ProcessNextLine()
takes next line from txt file (It's url) + navigate

but I want it to wait let the page load before calling "Call ProcessNextLine()" I tried System.Threading.Thread.Sleep not working?

View 12 Replies

VS 2008 BackgroundWorker1 Or System.Threading.Thread

Apr 25, 2012

What is the difference in using: BackgroundWorker1 or System.Threading.Thread

View 3 Replies

Multi-threading Scoping - Enclosing The Test Module Portion That Hosts The Delay In A Synclock Results?

Jul 16, 2010

I'm on my way to MSDN but thought I'd stop by here first because the answers are usually more cogent.I have a test bed that mimmicks my product app. The general architecture is a factory that builds/instantiates a number of objects (device controllers) that are scalable in number based on requirement. Each object has a threaded portion that reads a device. This way, each object can read its own device simultaneously with all the others. To perform the read, the object calls a routine in a Module that houses the device interfaces. Interestingly (and happily), it seems like each thread has its own copy of the Module routine.

The test bed seems to verify what I'm seeing in the app. In the testbed, a 500 mil second delay is substituted for the device call. Even enclosing the test module portion that hosts the delay in a Synclock results in multi-threaded execution of the pseudo device call. I haven't tested for data yet, but this seems to indicate that when the module routine is called from controller object, it too carries it's own copy of the data just like the calling object. As a long time c++ programmer...that don't quite seem right.

View 2 Replies

Multi-threading - Cross-Thread Operation Not Valid

Aug 25, 2009

I looked around the site and the questions I found relating to this subject were for C# (the application that I am maintaining is written in VB.NET), so I apologize if I overlooked one. Here is where I am calling my thread:

[Code]...

View 5 Replies

Threading Monitor.Wait() - Releasing Locks On A Thread

Apr 9, 2011

I have a problem with releasing locks on a thread. [Code] If Me.IsStarted Then 'checks if my service is started and ready of service requests 'code here to enqueue my job and objRxResult with the service so it can populate it with the result before Pulsing back 'the service has its own thread that it dequeues jobs off of and processes them on it own time 'during this key enqueue phase we block attempts to stop the service, thus the _objIsStarted lock [Code].

View 4 Replies

VS 2008 [Multi-threading] How To Run This Code In A Separate Thread

Apr 21, 2009

I am creating an IDE for a game script with similar functionality as the Visual Studio IDE (at least, some of it). The game script consist of code that looks visually a bit like C code. It uses braces to define the start and end of a 'class' and uses nested braces to define the start and end of an 'event' in a class.

What I want finally is to have two Comboboxes above the text editor, one that lists each Class and the other listing each Event. The comboboxes should also show the Class and Event that the caret is currently in, just like in Visual Studio.I have attached an example of such a script (you can open it with Notepad).However, here is a short example where you can also see how I "defined" classes and events:

class1
{
event1
{

[code]....

As you can see, the classes are the 'names' of each block of code, defined by matching braces { }. The events are the names of each nested block of code, also defined by matching braces { } but inside a class. There is only one level of nesting.As you can also see, the layout can follow the standard C-style layout, or a slightly different layout (using the opening brace on the same line as the class/event name), or even a completely chaotic mess. As long as the braces match correctly, the code is valid.So in short, the large blocks are classes, while the nested blocks are events.

What I want to do, is parse an entire script, and store all the Classes (and eventually, also all the Events, but let's forget about them for now). I want to store the Class name, start position (defined as the start index of the name), end position (defined as the index of the closing brace) and the full text (defined as the text between start and end position, so including the name).

vb.net
Public Class clsClass
Private _Name As String

[code]....

The code works basically by finding every first opening brace (the opening brace of each CLASS, not event), and then loops through the class (using a brace counter to keep track of the nested braces) until it found the last closing brace. It then stores the name, start, end and fulltext in a new clsClass and adds it to the list to return.

View 3 Replies

Will Modifying Shared Methods Change The Class That Reference Them

Jun 4, 2011

I'm wondering what will actually change a class, in the sense that serialized objects of this class will no longer be recognized. If the class has reference to shared methods of another class. Will changing such shared methods also change the classes that reference them?

View 3 Replies

Multi Threading - Crashed GUI - Executes A Sub Of My Choice On A Separate Thread

Sep 11, 2011

How can I make my apparently so that when I click a button, it executes a sub of my choice on a seperate thread? I need this to send an email and when I ran it normally it crashed my GUI.

View 1 Replies

Multi-threading - Thread Starts When A Button Is Clicked But Can't See The Result?

Sep 13, 2008

I am using a background thread in my application. The problem is: this thread starts when a button is clicked and it works well. After finishing it's work i can see the result. But when i try to start again, it gives me an error. How to restart a thread?

[code]...

When i press ToolStripButton1 for the first time it works really well. But when i press it second time it shows me error that, the thread has already been started.How to resolve it? I think how to restart thread is my question.

View 2 Replies

System.Threading.Thread.Sleep My.settings In Seconds And Not Milliseconds

Apr 14, 2012

I want to have My.Settings.Delay in seconds not milliseconds adding the 000 for the user. I tried My.Settings.Delay + 0 + 0 + 0. but can't sort how to do this.

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim var As Integer
Dim startVal As Integer

[code]....

View 4 Replies

VS 2008 System.Threading.Thread.Sleep Doesnt Work

Aug 22, 2009

I cant get System.Threading.Thread.Sleep to work..[code]

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

VS 2008 - Use The Threading.Thread.Sleep(2000) Code The Form Becomes Unresponsive

Jul 20, 2010

The coding that I have a problem with might make people think that I am creating some malware. So the project I am doing is associated with iTunes. iTunes allows people to have one library. There is another way, but it is very confusing to some people, and very unreliable. So my project is that I will allow people to have multiple iTunes libraries on one computer. So the problem is this. In order to have an option to choose your library, I gotta make sure that iTunes is not running.

So this is the script:

Private Sub CheckAndCloseiTunes()
retry:
'Custom class that includes the function to safely close iTunes
Dim Processes As Process() = Process.GetProcessesByName("iTunes")

[CODE]...

So when I use the Threading.Thread.Sleep(2000) code, the form becomes unresponsive.

View 4 Replies

Abort Menthod Of Thread Class Is Not Aborting The Thread?

Apr 1, 2010

I am using vb.net 2005In my form load procedure I am starting a background thread.The thread is declared as public.

Public
threadMonitorWMI As System.Threading.Thread
And started in form_load

[code].....

View 2 Replies

BGW In One Class And The Long Process For The BGW (DoWork) In Another Class Or Module?

Nov 16, 2009

I' ve got a short question concerning BackgroundWorker.Is it possible to have the main code for the BGW in one class and the long process for the BGW (DoWork) in another class or module?

I couldn't find anything helpful on the internet.Here is my code - DoWork in a separate class doesn't work:

[Code]...

View 15 Replies

Format A String Into System.Threading.Thread.CurrentThread.CurrentCulture.DateTimeFormat.ShortDatePattern?

Oct 14, 2009

I have a string in which for sure there is a date in the following format: YYYYMMDD. So, to identify 14 October 2009 I'll find 20091014.Having this string, how can I format into System.Threading.Thread.CurrentThread.CurrentCulture.DateTimeFormat.ShortDatePattern?

View 4 Replies

Update A WPF Control From A Background Thread From A Module?

Jul 2, 2011

My application has a total of 1 form. I have several modules, one of which is a module that handles a background worker dynamically. But what I need to be able to do is update a textbox from the background worker thread. Again, this code is contained within a module, not directly on the main form, so I am totally clueless as to how to make a reference to it. It's easy in WinForms, but I can't for the life of me figure out how to do it in WPF...

View 4 Replies

SyncLock / Multithreading - Child Thread Reading The Values Of _do At The Same Time As Another Child Thread Is Reading The Values

Nov 13, 2009

I have a dictionary object (let's call it _do) I am using to cache some values for use in a multi-threaded program. I have a single controlling parent thread, with a timer function _doTimer() which can kick off child threads with a new instance of class MyThreadObject in each. My parent thread has _do as a property and with each time _doTimer() gets called, it may or may not repopulate _do depending on cacheflag settings. I pass a reference to _do to each instance of MyThreadObject and those threads at some point read the values of _do but DO NOT write to it.

What I want is to ensure that the child threads do not try and read _do whilst the parent thread is writing to it. Same thing but very slightly different -> I also don't want the parent thread to write to _do whilst the child threads are reading from it. However there is no problem with 1 child thread reading the values of _do at the same time as another child thread is reading the values - so ideally I do not want each child thread to completely lock out read access, only locking out Write access.. The code is roughly like this:

[Code]....

View 3 Replies

Modifying Program Means Modifying One Aspects

Mar 16, 2011

Locality Not repeating code..Modifying program means modifying one aspects.

View 11 Replies







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