How To Make Activator.CreateInstance Threaded
Nov 5, 2011
I have some code that runs within a multithreaded class.Basically i create many threads which contain instance of this class.Within this class i create an object to either a vb6 or .net dll using reflection, then i call a method within that object. The object that gets called can be different every time.But for some reason even through i have multiple threads going when i get to the Activator.CreateInstance it is no longer multithreaded. I want to catch the error returned and put it in a log.
If UCase(pRow("TypeVB6").ToString()) = "TRUE" Then
classType = Type.GetTypeFromProgID(ClasstoInstantiate, True)
Else
[code]....
View 1 Replies
ADVERTISEMENT
Jun 7, 2012
how might I redo this method with Activator.CreateInstance
Public Overridable Function setCreditType() As CreditType
Select Case creditTypeId
Case Is = 0
Return New NewCredit(Me)
Case Is = 1
[Code]...
View 1 Replies
May 24, 2011
I have a type (Human) and I want to know if I could do System.Activator.CreateInstance(Of Human)(). So basically I want to check if Human has a public parameterless constructor / or a public constructor with optional parameters that make it possible to call New Human without giving any arguments.Is it possible to check beforehand if ystem.Activator.CreateInstance(Of T) will fail? (I mean other than wrapping the statement System.Activator.CreateInstance(Of Human)() in a Try Catch of course..)I've tried this but it doesn't work:
Option Strict On : Option Explicit On
Module Test
Public Class Human
[code].....
View 4 Replies
Apr 8, 2011
I'm trying to create a new instance of a Dictionary(Of String, ??) based on a ItemType variable I have. How do I construct the DictType so that I can use Activator to create an Instance of the type I'm after?
Dim ItemType As Type ' Data type of dictionary value
Dim DictType As Type = ???? ' Dictionary(of String, ItemType)
Dim NewDict = Activator.CreateInstance(DictType)
View 2 Replies
May 17, 2011
I am usng a multi threaded process to fire off a task, but when it is completed I want to make a label visible on the main form (form 1), eg "process completed", however the code I have in place comes up with the following error message;
Cross-thread operation not valid: Control 'lblCompleted' accessed from a thread other than the thread it was created on.
View 4 Replies
Apr 12, 2009
I'm trying to put together a plugins system with .NET, and I'm not sure if I'm doing it correctly. The basis of the system is that a specific directory ({apppath}/Plugins/) will have a bunch of precompiled DLLs, and I want to look through each one with reflection, and for every class available, if it inherits a specific base class (this is defined in yet another DLL, but I'll go into that later), then create an instance of it and call a specific function in said instance.
Public Sub ScanPluginsInDirectory(ByVal Directory As String)
Dim Plugins As New IO.DirectoryInfo(Directory)
Dim Files As IO.FileInfo() = Plugins.GetFiles("*.dll")
[CODE]................
The specific problem I have is, I'm not sure this is the right way to do this. Would the method I'm trying to do work, if it can be assumed that A.Plugin() actually exists and any structures and classes referenced here are bug-free?
View 2 Replies
Sep 5, 2011
At the moment i'm creating a remote object instance by:
Dim serverURI = String.Format("{0}://localhost:{1}/{2}", IPC.Protocol, IPC.port, IPC.Channel_name)
Me.Server = CType(Activator.GetObject(GetType(RemotebaleServiceCommands), serverURI), RemotebaleServiceCommands)
I need to pass some constructor arguments to RemotebaleServiceCommands call.
View 1 Replies
Jun 28, 2010
How does the Windows activator know whether to activate an executable in 32 or 64 bit mode?
View 11 Replies
Apr 11, 2011
i created a threaded form class that i call when i know an update is going to take a while....it is a simple form with a label and an animated marquee progress control. the code is listed at the bottom....whenever i try to set the message, it says i cant do it with error "{System.InvalidOperationException: Cross-thread operation not valid: Control 'MessageLabel' accessed from a thread other than the thread it was created on." from my form (in my SAVE function, i put the following line:[code]....
View 6 Replies
Jul 21, 2011
I'm trying to run a multi-threaded console app in VB and am having thread cross-over. Basically I want to run 5 threads, have them continually access a queue, process, and repeat until there's nothing left. When all threads have processed I want them to do something else.I'm attempting to use SyncLock to prevent multiple threads from accessing but it does not seem to be working.[code]
View 3 Replies
Nov 24, 2008
Here is my webclient class that I am using to check multiple web sites at the same time. I am threading the class so each thread is creating a new getHtml Class. It seems that it still is waiting on something, because it only returns about 2 pages per second, which is great, but I think it should return faster if they are truly running on separate threads.When i made a similar perl script it would return 50 pages in about 10 seconds so it was much faster than this webclient method, unfortunately I don't want a cli. Let me know what you think. I have tried setting the proxy to null, but that didn't do anything.
Class getHtml
Friend result
Public Sub GetPage(ByVal URL As String)
[code].....
View 4 Replies
Apr 25, 2012
I beleive I have asked a question similar in the past but I am re-visiting it with a slight difference and wonder if anyone can give advice.I am building a server app that when starts it opens a second 'listener' thread that when started will open up a listener on a port and wait. When a client connects it handles it and upon disconnects starts from the top and waits for the next client. Also once a client has connected its job is to look at a list of ports see what is free quickly respond with a port number setup another thread which then listens on the port number for the client.
At pretty much all times the 2nd thread will be stuck on a line waiting for a connection and at any one time there maybe more threads running waiting for a client to connect and if a client connects it never ends the thread as its stuck on a line of code.
Now currently if the service gets a request to stop it cannot stop the threads because they are just waiting on one line of code for a client to connect. I can easily set a varible to indicate the service is closing but they can only check that once a client is connected so the code is run.
What I either want is:
a) a way of force closing a thread from the main app thread or
b) a way for the line of code waiting for a client to connect to timeout after a certain amount of time.
View 7 Replies
Jul 14, 2010
This is my attempt to create a ObservableCollection in VB that is WPF thread-safe. Can you think of any problems it may have?
[Code]...
View 2 Replies
Apr 30, 2009
I created an image-viewing control for my boss that incorporates panning, zooming via the mouse wheel, and drawing a box to zoom to. The control needs to support very large image files (i.e. several thousand pixels on each side).
It all works, but whenever the code is scaling the image the control UI becomes unresponsive. My boss had me use threading to set the scaling code apart from the UI. The scaling code is now definitely on a separate thread but the UI is still bogged down while scaling code is running!
View 4 Replies
Aug 10, 2011
I'm trying to teach myself how to create multi-threaded applications in Visual Basic Express 2008. I found a page headed "Creating Threads and Passing Data at Start Time" in the Library here -
[url]
However, I can't get any of the examples on that page to run. I pasted the code from an example into a new Project in my IDE but pressing F5 just gives me build errors which I have no idea how to resolve. It's probably something trivial but I can't progress with these examples. Please can somebody tell me what I need to add to get them to run
View 1 Replies
Apr 5, 2011
I am drawing five images in a row. The five are the same thing at five different zoom levels. Therefore, only one of the five will be displayed at any one time, but the others have to be there because there can be over 100 images being displayed on the screen at any one time, and each drawing is quite complicated. If I were to draw them all on the fly, then zooming would require that all 115 images be recreated and redrawn with each zoom. That's painful. To avoid that, I draw all five zoom levels of each image. When the user iteracts with the form, they will be interacting with, at most, two of the images, so when they interact with the form, only two of the 115 have to be redrawn, though those two have to have all five zoom levels drawn, for a total of 10 images.
[Code].....
View 14 Replies
Nov 11, 2010
I've just completed my first multi-threaded task under windows. Historically I am a VMS Engineer. You could multithread in drivers in VMS but VMS never had formalized threads. Which means it never had applications threads. Threads will become increasing important in the future. I thought this maybe a good time to discuss them. Not having access to sources hurts in terms of the amount of depth one can achieve in Windows. Some of the topics for this thread might be...compute resource regulation, how to do multi-threading and of course things to watch out for.
View 1 Replies
Mar 4, 2010
How do I pass a variable to a threaded procedure? The clickedItem.Tag contains a username as a string which I want to pass to Public Sub GetLockoutInfo(ByVal UserID As String) but the AddressOf GetLockoutInfo line doesn't allow for a parameter to be passed to the procedure.
Private Sub CallGetLockoutStatus(ByVal sender As Object, ByVal e As System.EventArgs)
Dim SearchUserDetails As New NiRDs_Functions_OC
[Code].....
View 2 Replies
May 18, 2011
I am firing a threaded process using (checkfile is my sub):
mythread =
New System.Threading.Thread(AddressOf
checkfile)
mythread.Start()
THe problem is that it doesn't seem to be working the way I anticipated. Whilst the process is actually being run in the background, the main UI is just frozen. This is highlighted by the gif animation i wanted to have animating (eg. like a ticker) whilst processing, actually coming up as a static image. As soon as I click anwhere on the UI i get the "Not Responding" message at the top, plus the button that executes the thread still seems to be depressed and has the orange glow around it.
View 5 Replies
Nov 17, 2010
I have a mutex and threaded related question about = Run one or the other per call to routine
[Code]...
View 2 Replies
Nov 3, 2011
Add an ArrayList To Threaded Listbox i have been working on this for ages and cant get it to work. here is what i have so far... this gets dup sub to work in new thread when i click button2 the dup sub will filter through Listbox2 items and sort through the listbox and if it isnt a duplicate it will add the line to an arraylist i now need to the array list (decleared as arr) to go into listbox2 in short i need to make this line of code work as a crossthreaded call
[Code]....
View 1 Replies
Mar 12, 2011
I have written a rather complex dll for processing a large volume of data (~4,000,000 records) from an Oracle database. It works well, but takes about 23 hours to run.Since I wrote the code fairly compartmentalized I realized that there are 6 routines that should be able to run concurrently, and I have a multi core processor,I decided to try my first multi-threaded implementation.
In the routine I am working on I am doing no I/O everything is in memory in variables. My data is already in dataTables and hashTables. Most of the data is defined as private in the class scope, but no conflicting updates should happen because the code segments works very distinct portions of the dataTables.The concept is simple, I have 2 routines that need to complete before launching my threads, and one routine that needs to run after all of the threads have completed. Here is what I am trying;
ProcessDXDate()
ProcessHistology()
aryThreads(0) = New Threading.Thread(AddressOf ProcessLaterality)[code].....
View 7 Replies
Oct 22, 2009
I'm using VB.NET. I want to build a large List (Of MyClassOrStructure) that becomes static after its initial population.I'm going to have multiple threads that need to iterate through this list to read data (no writing, inserting, or deleting)
Are there any very bad things that I need to keep an eye out for?
View 3 Replies
Oct 12, 2009
I have written a small GUI based vb.net program that speaks to embedded devices via the com port. The GUI code contains a class which all communication to the embedded device is handled through (com port device, communication protocol, parsing info, holding device related info after each read).That class is called EDComms.
I wanted to add a thread so that the EDComms object could run in the background and report back as it downloads logs files and such (It can take a while to get log files from the device sometimes).So. Should I have EDComms inherit from backgroundworker thread? Or should I have a background worker thread as a member of EDComms?Right now I am going with the second choice. The only thing I have to do now is write a func for registering two delegates from the GUI for notifying task progress, and notifying task complete.Or is there a better choice than these two I have presented Perhaps have the thread as a member of the GUI?
View 2 Replies
May 11, 2011
I am running into an issue with changing properties of controls on a VB.net project that I am working on. The portion of code that I am having trouble with is re-enabling a couple of buttons and a ComboBox after a Threaded operation completes. The point of it is to disable the buttons after clicking the main "run process" type of button (called cmdCrawlSearch) so that the process can run on a new thread while the form is updated with the status. I was able to learn about Thread Safe calls using delegates in order to update the Text property of the TextBox (txtOutput) on the form, and thought that enabling buttons would be just as easy, but when I am trying, I am either getting an "Object reference not set to an instance of an object" exception, or an "Exception has been thrown by the target of an invocation" exception (from the current version of code) with the InnerException being the Object reference exception. I am posting the portions of code related to the issue, then below it is the InnerException name and stack trace. Perhaps I am not using the Delegates correctly (since I still do not fully understand what can and can't be done using a Delegate.) Or there is a better way to do this.
[code]...
View 2 Replies
Feb 1, 2011
I am trying to create a proxy checker. This is my first attempt at multithreading and it's not going so well, the threads seem to be waiting for one to complete before initializing the next.
[Code]...
View 2 Replies
Aug 27, 2009
Raising events in multithreaded classes?
I am running a class(gamepad handler) that uses many child threads to check for key input and the like then it raises events to my form to sort out the needed reaction, Is there a way to make the event raises on the same thread as the class itself.
View 3 Replies
Nov 14, 2009
I'm having some trouble creating a multi-client server / client thingy.So far, I've used Atheist's example and allowed the clients to successfully transmit information.However, whenever I send more than 1 message to the server at the same time, the server bugs up and does not receive the message at all. I suspect it has something to do with the DoRead method reading from both clients and stuffing it up or something.
View 13 Replies
Jul 23, 2009
how to re-write my application (http:[url]....) to be multi-threaded using the background worker. The use case is something like:
1. User opens a binary file, it can be several Gbytes in size so reading it into memory isn't practical.
2. User can then navigate through the file in 188byte chunks, data is read from disk, decoded, and displayed for each chunk in turn.
3. User may want to search for some data or build a report. This will involve repeating the read, decode, display, function multiple times. During this looping the GUI stops responding and there is no option to cancel so I want to make it multi-threaded. So, is it safe to open the file in the GUI thread and then read from the file in the background thread? I currently use something like this to open the file once:
Dim fi As New FileInfo(filepath)
fs = fi.OpenRead()
and then in a separate sub multiple calls to:[code]..........
View 4 Replies
Jun 5, 2011
I'm having a small issue; I start a process and when that process exits, I raise an event which removes a control from my form.It all works perfectly until the part where I want to remove a control from my form. Visual Studio gives me a cross-thread exception even though I'm programming single threaded.
View 6 Replies