Abort An Asynchronous Method Call After Timeout?
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
ADVERTISEMENT
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
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
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 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
Mar 27, 2009
Is webbrowser.navigate method is synchronous or asynchronous?
example:
dim ct as integer =0
dim counter as integer =0
ct+=1
wbb.navigate(""http://www.yahoo.com")
counter+=1
will counter get increased after firing webbrowser.document completed event?
View 6 Replies
May 11, 2010
I have a routine that will connect to a tcp server and then disconnect which works perfect. It checks the connection to another program on another pc which is what I need. But if the computer is not on or the ip address is not valid, it takes a bit for it to time out and continue on.
how to add a timeout of 2 seconds to the following code?
Private Function CheckServer(ByVal IP2 As String, ByVal Port2 As Integer) As Boolean
CheckServer = False
[Code]...
View 3 Replies
Jun 4, 2012
Background: My application is used to execute tests using Selenium RC servers, and occasionally I'm running into a problem when my call to a Selenium command doesn't return the response from the RC server - it then ends up blocking the thread that is executing the test.
[Code]...
View 1 Replies
Sep 14, 2009
my application has integrated an external library with long running math-evaluations. It happens that some calls to functions in this library start but do never come to an end.
Unfortunately I have no chance to look examine the behaviour of the library. So I got the idea to stop my function calls to the library after a timeout.
Has anybody an idea how to manage this an to control the execution of a function, i.e. to stop it hardly after a certain time?
View 1 Replies
Nov 12, 2009
Does calling the Dispose method on a Windows.Forms.Timer call it's Stop method? Or should I stop the timer before I dispose it?
View 5 Replies
Feb 16, 2010
I will try to explain what I need.Let's say that I have a class like this:
Public Class Example1 Public Sub ToBeCalled()
[Code]...
View 5 Replies
Jan 29, 2012
I have a Application that Crypts all Files in a Directory and the Subdirectories
Public Shared Sub CryptAllFiles(ByVal crypt As Object)
'check if this dir exists
Dim vDirInfo As New DirectoryInfo(vPath)
If Not vDirInfo.Exists Then Exit Sub
'get all files' sizes in current path
[Code]...
View 3 Replies
May 3, 2011
I'm not sure if this is a VB.NET error or SQL Server. But I get the above error with following stack trace:
[SqlException (0x80131904): Timeout
expired. The timeout period elapsed
prior to completion of the operation
or the server is not responding.]
System.Data.SqlClient.SqlConnection.OnError(SqlException
[code]....
View 3 Replies
Mar 17, 2012
i want to which way is better when concentration is on processing speed. i want to call a method that compute some data that method is on another form in my windows form application then what you prefer is better way 1) to call that method in another form and use returned value or create similar method in form where it is required.i want to make it's processing fast.
View 3 Replies
Jun 27, 2011
Assume I have a function: Protected Sub UploadFile(file As String)
End Sub Then I can do the follwing
UploadFile(file)
But I would like to do this: file.UploadFile()
Looks like Im missing logic in here, but still - is it possible to make dot-like notation?
View 2 Replies
Dec 29, 2009
I have a class that runs as a thread. While the thread is running, I want to call a method in that thread. I do this commonly where a thread calls a method in the GUI with a delegate. But I'm confused how to do this when the called thread is not the GUI and there are no parameters passed to the called method.
View 8 Replies
Apr 3, 2009
may I just ask a seemingly simple question for which I can't find any solution throughout all the VB.NET documentation: I have to call a (non-static) method of another object (instance!) based upon the name of the method (given as a string).
View 1 Replies
Jun 21, 2010
I have a Form1 with a method called OrdreUpdate2 I try to run thad method from another form by using the command Form1.Ordreupdate2 in a buttonclick.
But nothing happens..What am I missing here?
View 1 Replies
Nov 5, 2010
I have a form and I am calling a method from a module in that form. However, how to do i call the object into the method, since Me doesn't work.
Example:
in the module:
Function printname()
Console.WriteLine("Form called with is titled:" + me. text)
[code]....
View 7 Replies
Jan 27, 2011
In VB .NET, when you create a user control class, you have the obligation to call the sub InitializeComponent within the constructor.If you don't you'll a warning message like this: [code]What is the mechanism used to raise this warning? Is it something I can reproduce for my own functions?
View 1 Replies
Apr 6, 2011
i have a problem i use a call sub procedure to do a delete records in my database for my vb .. now i have a problem when i call my sub delete proceudre in like this call GetDelete("tblName") , but in the sql query the sysem declare like this delete * from 'tblName' in my sub procedure when i set the breakpoint in which cause an exception error "Syntax error in query. incomplete query clause " anyway how to delete the quotes so i can retreive it without error
View 2 Replies
Jun 3, 2010
Is it possible to dynamically load a .NET DLL and create an instance of a class inside it? I will know the name of the class.
View 5 Replies
Jul 22, 2009
When should I call the Flush() method (TextWriter.Flush() / StreamWriter.Flush() / BinaryWriter.Flush() / etc) ? Should I call it everytime I finish writing a stream?
View 3 Replies
Mar 3, 2010
I have a method written in VB.NET. It looks like this:
Shared Sub SomeMethod(ByVal Id As Guid,
Optional ByVal str1 As String = "foo",
Optional ByVal str2 As String = "")
I want to call this method from C# 3.0 and I want it to use its default arguments. I tried passing System.Reflection.Missing.Value, but I cannot cast it as String. Is there any way to do that?
View 3 Replies
Jan 31, 2011
I want to calculate the time taken by a method to execute.[code]...
View 11 Replies
Oct 28, 2010
I have a C# dll and want to use it in VB.NET. I'm using C# 2008 Express and VB 2008 Express. I have added a reference in a VB project to the C# dll. When I create an instane of a class in the C# dll, it gives the following error messsage: "Type 'RF.RabinFingerprint' has no constructors". My C# dll code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;[code].......
View 3 Replies
Apr 21, 2012
I have a method called ADD in a class that connects to a database. The database class name is XDB. I also have an object named XXX in it's own separate class with properties.One of the instructions for the Button named ADD click event is:
'Call Add method passing in the XXX object
So this is how I coded:
'declare a variable X as an object instance of XXX
Dim X As New XXX[code].....
I know it's wrong since it doesn't add the XXX and the form doesn't close but I don't know what I'm doing wrong.
View 6 Replies
Jan 3, 2011
REF: http:[url].....The above reference is where I got the code below.This code adds buttons to Form1. When a button is clicked a messagebox appears stating what button was clicked. I want to have the ClickHandler fill a RichTextBox on Form1 (I added a RTB to Form1). My problem is I can't do a Dim xForm As New Form1 to fill the RTB from the ButtonArray Class. I can place my file's text in a MessageBox so I know the code I added is correct. I also tried placing a Property method on Form1 and using a Accessor to fill the RTB, however it also requires Dim xForm As New Form1. How can I get my data from files to the RichTextBox on Form1 from the ClickHandler in the ButtonArray Class? See ButtonArray Class Below.
Imports System.IO
Imports System.Text
Imports System.Collections.CollectionBase[code].....
View 5 Replies
Jun 8, 2009
I am trying to call a method which has two parameters using thread. How can I do this? If I pass parameter to my thread.start() method, it is giving error.
View 1 Replies
Apr 30, 2012
I am new to Silverlight, but am up to my ears in some of the more intermediate/advanced stuff.
I am using MVVM, in Silverlight 5.
I have a view (we'll call it ComboView.xaml). It has a ViewModel (we'll call it AwesomeVM)
The view contains the ViewModel, declared in the page's resources like so[code]...
View 1 Replies