Why Asynchronous Operation Is Slow
Feb 2, 2012
I am using a BackgroundWorker, an OleDBDataReader, a DataGridView to retrieve records asynchronously from an Access database. I call ProgressChanged event from the DoWork event every time I retrieve a record. In ProgressChanged event I add that record to the DataGridView and also update a label. There are about 2000 records to retrieve.I have two problems:Although I'm running an asynchronous operation, the UI remains unresponsive unless I use Thread.Sleep() inside the DoWork event (Why?). Using Sleep() method with an argument of 1 causes the process to run 20 times slower! (Process takes about 1 second if I comment out the 'Threading.Thread.Sleep(1)' line, compared to 20 seconds if I use it.) What can I do to get a responsive UI and a fast background operation (at least not 20 times slower!)?The other problem I am facing is: if I close the form while the asynchronous operation is ongoing, I get this exception (I think in the ProgressChanged event): Exception has been thrown by the target of an invocation. I tried using FormClosing event to end the process but no luck. How to fix this?
View 5 Replies
ADVERTISEMENT
Jan 4, 2012
I'm trying to convert code from Delphi to .Net. I'm stuck on one line:
//Delphi code ss := Copy(ss, Length(ss), 1) + Copy(ss, 1,Length(ss) - 1); 'vb.net code ss = ss.Substring(0, ss.Length - 1) + ss.Substring(1, ss.Length - 1)
Delphi combines the two substrings, while .Net just concatenate them like a copy.
View 2 Replies
Aug 17, 2009
I have this code obtaining data from a sensor that is sending a string that contains 4 numbers separated by a tab and terminated by an end of line/ I am trying to use an asynchronous callback to get the data over TCP. That problem is that the callback function is not grabbing the complete string. Sometimes it will, other times it gets half in one retrieve and half in another. I need the callback to hold off until it gets a newline character.
Code:
Public Sub readVaisala()
Dim ip As String = "192.168.1.30"
Dim portNumber As Integer = 23
Dim time As Int32 = Now.Second * 1000 + Now.Millisecond
[code].....
View 2 Replies
Feb 18, 2011
How can I set up an asynchronous web service in asp.net?
I want to call a webservice to post some data to a database, but I don't care if the response failed or succeeded.
I can use .net 2.0 or 3.5 only and it can be in vb or c#.
View 3 Replies
Mar 15, 2009
I have a small VB.NET application built using VS 2008 and .NET 3.5.Very simply, there is a timer that kicks off every few seconds to download an XML stream from the web. I look at this stream and manipulate it.The problem I am facing is that the remote web server may not respond in a timely fashion to the following line of
[code]...
How can I implement asynchronous calls so that the my application can behave without locking up?
View 3 Replies
Feb 1, 2010
I have a class with a mthod which does a a time consuming task. I know how to start the method in a separate thread using the Threading.Thread class. What I want to do is use callback so as to have the method report its result to another method when completed. I chose to use the asynchronous Begin/End call pattern.
Private Function BeginConnect(ByVal URl As String, ByVal callback As AsyncCallback, ByVal state As Object) As IAsyncResult
'Some Code
End Function
[code]....
View 13 Replies
Feb 23, 2010
i'm creating an Asynchronous socket programming in vb.net. i've utilised the code from Asynchronous client and server code frtom the following links:m a new user so could post only one link fully)When I try to connect the for more than one client the second client always waits until the first clientcompletes the call. i want the clients to accept calls at the same time
View 1 Replies
Oct 12, 2010
I am writing web services with VB.NET (2.0). The client side will use different technologies such as Java and Siebel. So, if I write asynchronous web services, is it possible for different platforms to consume them? I know it is quite easy with a consumer having .NET platform, but not sure for different platforms. Is it enough for them to have asynchronous ability, or should it be a similar platform?
View 3 Replies
Feb 12, 2010
I noticed that HttpWebRequest freezes the UI while it's waiting for a web page to be downloaded:
[code]
If someone's done this before, what is a good way to keep the application responsive?
View 4 Replies
Oct 15, 2011
I made a TCP server which communicates with multiple clients at once, but I can't seem to be able to make them stable. When one of the client sends 100 packets to the server, the server receives only a few of them.Here's the client code in PasteBin. It shows how the client connects to the server and then sends 100 messages in a For loop to the server.And here's how the server handles the connection. I couldn't paste the full source as it's hundreds of lines long so let me know if it's missing any mandatory parts and I'll upload them as well.
View 1 Replies
Jan 9, 2010
I create an automatic ftp file downloader by using FTPwebrequest. In which, is there any possible to download multiple files simultaneously using Asynchrounous and threading concept?
View 1 Replies
Jan 24, 2011
I'm using asynchronous to send/receive from a website I want to block the BeginGetRequestStream method which I have done, using
Code:
WaitEvent.WaitOne(1000 * 20, false);
the problem is that it blocks the UI, which I thought it did not so it basically works like GetRequestStream which does block the UI.
View 3 Replies
Jun 3, 2011
I basically have a few thousand transactions 7,000 - 10,000 transactions to process over a short time. The flow goes like this.
---> ----> ---> ---> receive (1000) as each transaction takes approx 2 seconds so if i were to process synchronously it would take all night......
Now first i would like to ask if i am going about this the right way ? the service i am communicating with is not .net but is built to handle large amounts of requests. I have obtained the following code that suggests it will do what i am after
dim strxmlreq as string = '(this is where i input my xml string)
Dim request As HttpWebRequest
' Create the request
[CODE]...
The problem i have is if the above will work for me where exactly do i catch the returned xml string ? I assumed "result" would be the xml output string.
View 3 Replies
Jun 9, 2011
Download file asynchronous using sockets
View 8 Replies
Feb 1, 2010
I have a class with a mthod which does a a time consuming task. I know how to start the method in a separate thread using the Threading.Thread class. What I want to do is use callback so as to have the method report its result to another method when completed. I chose to use the asynchronous Begin/End call pattern.
My thoughts are:
Private Function BeginConnect(ByVal URl As String, ByVal callback As AsyncCallback, ByVal state As Object) As IAsyncResult
'Some Code
[Code].....
View 4 Replies
Feb 12, 2011
I have been trying to figure this our for far too long and I cannot get my head around it. Every example I have seen seems to be far more complex that I need. I have a web service in my project (.asmx). I want to call it very simply from a button on a webpage.
Click
Run service asynchronously
return control back to webpage (web
service running in background)
View 1 Replies
Jul 12, 2011
The scenario is that an ASP.NET webforms page will call a web service in an async manner to make about 8 web service calls to various providers for data. I would like to run them in parallel to speed things up. I also need to wait for them all to come back before moving on.
View 1 Replies
Jun 16, 2010
I need to make an asynchronous call to a method which for the sake of simplicity counts from 1 to 100. If an exception is thrown during the methods counting process, lets say at 50 I need to stop the methods execution, dispose of a few objects and restart it at 51 but have no idea how to go about it.I basically need to raise an event from the method to the main thread and restart the asynchrounous method.
View 3 Replies
Jan 17, 2012
I am developing a form application in VB .Net with a main thread and two other threads that reading values from two serial ports, do some work and raising events to return values when each thread ends.The handlers for the events are in my main thread.Is there any possibility the two threads to raise events the same time or some other event (button click event for example) raised the same time with a thread finished event? What happened then? Is there a way to make asynchronous event raising?
View 11 Replies
Feb 6, 2011
I have closed the client socket using client.close() but netstat command shows the same socket in time-wait state.Because of this I am unable to reuse the socket..
View 2 Replies
Oct 6, 2010
VB.NET 2010, .NET 4/I have a System.Timers.Timer object that does some work on its elapsed event:
Private Sub MasterTimer_Elapsed(ByVal sender As Object, ByVal e As System.Timers.ElapsedEventArgs) Handles MasterTimer.Elapsed
MasterTimer.Enabled = False
'...work...
MasterTimer.Enabled = True
End Sub
My problem is that the work that it's doing sometimes gets stuck. Part of the work is serial communication so it might be getting stuck waiting for a response from something. I've already modified my serial communication code a bit to hopefully solve the problem. However, this timer is basically the heartbeat of a production control application and it is very bad if it were to stop for any reason. I was thinking that it might be nice to put in a fail-safe timeout so that, if the "work" is taking too long, the timer could re-enable itself and try again. I was thinking of something like this:Move the work into a subroutine and create a delegate:
Private Delegate Sub WorkDelegate()
Private Sub Work()
'...work...
End Sub
Call the work by invoking the delegate and then use WaitOne(timeout) on the IAsyncResult to specify a timeout:
Private Sub MasterTimer_Elapsed(ByVal sender As Object, ByVal e As System.Timers.ElapsedEventArgs) Handles MasterTimer.Elapsed
MasterTimer.Enabled = False
Dim workDel as New WorkDelegate(AddressOf Work)
[code]....
In that it would re-enter a subroutine that is already running? Is there a way to abort Work() if it hasn't finished after the timeout? In other words, just cease execution of Work() if result.IsCompleted Is False after WaitOne?
View 1 Replies
Nov 23, 2011
I am attempted to write a small asynchronous socket library that I can use to create a client/server application. I can get all of the code to run fine if I leave it in the form, however if I try to move it out into its own class, I cannot figure out how to update the form with connection status, things like that. Below is code, shortened a bit just to make this easier to read and type.
[Code]....
There is actually more to that class, but I never get anything after the first message goes out. I'm not sure where to go from here. I've tried lots of different methods that I've found on the google searches, some from here, some not.
View 1 Replies
Dec 2, 2010
I'm using the code at the bottom to connect to a Usenet newsserver. This code works fine, but it freezes the UI, so I need to do it asynchronously.
[Code]...
View 6 Replies
May 28, 2010
I need to build an an asynchronous encrypt/decrypt method but I don't know where to begin. I have only one requirement. I need to get a serial number like output for example:
ABC12-EFG45-POI98-KJUH8-KJSAK
I need to build a minimalistic licensing algorithm, where I want to create a serial number based on a salt, username, machinename etc.
My Sharepoint Blog [URL]
View 1 Replies
Jun 12, 2010
I recently worked on a small-scale EPP Client, which is a communications protocol over TCP/IP using XML packets to exchange commands and responses. The server I'm working with specifically is employing SSL so the code contains references to an SSLStream certificates and passphrases - please don't ask me to post more code than I provide here.We're building the XML EPP Commands in raw System.Strings, then using System.Text.Encoding.UTF8.GetBytes on the string to populate a Byte Array, then writing the Byte Array into the SSLStream. The server would communicate, negotiate certificates, and
View 10 Replies
Jan 31, 2012
A few weeks ago I wrote a wrapper for the ServiceController control to enhance and streamline the base ServiceController. One of the changes I made was to add a monitoring component using the System.Threading.Timer object. On any change of status, an event is raised to the parent class. The actual monitoring works fine, but when the event is handled in the main form, my program abruptly ends - no exceptions, no warning, it just quits. [code]...
View 1 Replies
Aug 13, 2009
I'm using ASMX web services in VB.Net in VS 2005. I am calling a function method on the web service that returns a true or false value. This works fine if I call the the web method synchronously, but if I want to call the method asynchronously, the function returns to a sub and there is no return value; therefore, I can't tell whether the result of call is true or false. Is there a way to make an asynchronous call and still get the true or false result (perhaps using the userState Object)?
For Example:
Dim MyResult as Boolean = MyService.GetResult(10)
Dim MyResult as Boolean = MyServer.GetResultAsync(10)
This doesn't work the compiler complains: "Expression Does Not Produce a Value"
View 2 Replies
May 1, 2012
I just have a simple vb.net website that need to call a Sub that performs a very long task that works with syncing up some directories in the filesystem (details not important).
When I call the method, it eventually times out on the website waiting for the sub routine to complete. However, even though the website times out, the routine eventually completes it's task and all the directories end up as they should.
I want to just prevent the timeout so I'd like to just call the Sub asynchronously. I do not need (or even want) and callback/confirmation that it ran successfully.[code]...
View 2 Replies
Jul 8, 2010
Im using Vb.net visual studio 2008. i have got a process(system.diagnostics.process) to be run in background and it updates the Ui thread progressbar and a label and i have worked it using backgroundworker.runworkerAsync. Now the problem is i have to work the same process for a number of time with different inputs.
The code block is :
Private Sub fnStartEvent(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.click
Dim inputFolder = Directory.GetFiles(textboxSourceFolder.text)
Dim currentNumberOfFile As Integer=1
[code]....
The problem in here is the fnStartEvent method once gets started, it calls BackgroundWorker1.runWorkerAsync process and that runs in a seperate thread and does not wait for the thread to complete and it moves to the next line of code i.e loops to the next item and it returns to same BackgroundWorker1.runWorkerAsync line and throws exception that it is already running.
Tried
1.
Private Sub fnStartEvent(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.click
Dim inputFolder = Directory.GetFiles(textboxSourceFolder.text)
Dim currentNumberOfFile As Integer=1
[code]....
But this does not updates the Ui thread used to denote progress.
2.Put the whole process inside the DoWork thread and loop for each file in there itself, but that to returns the cross thread error in progress bar updation.what is the standard procedure in executing a loop for the backgroundworker to wait for finishing as well as update the UI without blocking it.
View 1 Replies
Apr 9, 2010
I need to retrieve multiple objects from an external system. The external system supports multiple simultaneous requests (i.e. threads), but it is possible to flood the external system - therefore I want to be able to retrieve multiple objects asynchronously, but I want to be able to throttle the number of simultaneous async requests. i.e. I need to retrieve 100 items, but don't want to be retrieving more than 25 of them at once. When each request of the 25 completes, I want to trigger another retrieval, and once they are all complete I want to return all of the results in the order they were requested (i.e. there is no point returning the results until the entire call is returned). Are there any recommended patterns for this sort of thing?
[Code]...
View 2 Replies