|
|
Cool
|
|
|
|
|
I'm designing an application which consist of multiple clients that connect to a server using sockets. I'm trying to figure out a way to monitor the connection and if no data is transferred within a certain time from (say 1 minute) then the connection is closed (basically I'm trying to create a watchdog timer).
From what I've been reading it seems that I would need to use the AutoResetEvent class. The way I envisioned it working is that every time the server receives data from a client it resets the timer of the AutoResetEvent.WaitOne. What I've come up with so far is something like this in the server application:
Dim autoEvent as New AutoResetEvent(False)
If autoEvent.WaitOne(1000) Then
autoEvent.Reset
Else
Close connection and inform user
End If
When the socket receives data it will call autoEvent.Set which will cause the autoEvent.Reset method to be called. This would obviously be started on a new thread so it wouldn't block the main thread handling the data.
Is this correct or is there a better way to do this? Any links to creating a watchdog timer would be appreciated also. Thanks in advance for any help with this.
|
|
|
|
|
That seems like the best way to do it to me. BTW, your timeout is set to 1 second, not 1 minute. That could be for testing purposes. Just sayin'...
|
|
|
|
|
The timeout I just wrote that for the purposes of the post. When the autoEvent.Reset is called (as a result of autoEvent.Set being called), will the code in essence jump back to the autoEvent.WaitOne or will the code jump to after the If...Then...Else block?
|
|
|
|
|
|
Hi guys this is simple but I'm a novice trying to cache the getMyresult function but I'm struggling to find the code to do so, could you help please? . I don't want the answer just some of the methods and syntax.
Sub Main
console.writeline(getmyresult(2))
console.writeline(getmyresult(3))
console.writeline(getmyresult(2))
console.writeline(getMyresult(3))
End Sub
function getMyresult(X as interger) as integer
dim Y as integer=LongCompute(X)
return Y
end function
function LongCompute(X as integer) as integer
system.threading.thread.sleep(1000)
return x^2
end function
modified 20-Jun-13 14:00pm.
|
|
|
|
|
GetMyResult has to maintain it's own cache of result values. Create a collection to store Key/Value pairs, usually a Dictionary(Of Integer, Integer). The Key value will be the integer you pass in and the result will be the value returned by LongCompute.
Basically, when GetMyResult is called, it uses the value passed in to search the Dictionary for that value. If it's found, it can return the value associated with that key. If it's not found, then you call LongCompute with the passed in value, get the result, and add the new key/value pair to the dictionary. Lastly, return the result back to the caller.
|
|
|
|
|
Just curious Dave and Poster, but what does this mean in context - "cache"? I guess the simplicity of the code has me puzzled - two-stepping for a single computation. I can't see beyond that. I use a dictionary and actually truly cache with the class. Purpose?
|
|
|
|
|
To hold a table of values that have already been computed so you don't have to run through a potentially time-consuming calculation again to return the same value for the given input.
|
|
|
|
|
Exactly the same way that I do on the accounting side of my apps, but I exlicitly set out to cache. Sorry to inject! I had curiosity get the best of me as I was looking at the code and realizing that it is a textbook example has answered the question. Once again, sorry! Thanks for the replies, and let me know if you solve the threading problem. LOL ... Attempted multitasking this day.
modified 27-Jun-13 20:11pm.
|
|
|
|
|
Threading problem?? What threading problem??
|
|
|
|
|
|
Because his code is an example!
|
|
|
|
|
Dear Dave,
Many thanks for explaining it to me as well instead of just giving me the code,
My teacher will be impressed haha
Many Thanks
101
|
|
|
|
|
Prissy,
Thank you very much for the code I appreaciate the help im glad Dave explained it to me as this would of been cheating :P
|
|
|
|
|
I don't do it any other way! Good Luck!
|
|
|
|
|
Is it VB 6 or VB .NET? I don't know about return statement in VB 6? I'm forgot to choose Question. Oh, it's a VB .NET Discussion. I don't know. Sorry.
|
|
|
|
|
|
I use System.threading.timer() to read RS232 data periodically,
But I found it seems the threading.timer() produces many threads,like each cycle it use a new thread to read.
Is the threading.timer use many threads of threadpool?
|
|
|
|
|
How are you using it? Creating it once then just handling the event, or some other method? Can you post the code where you instantiate it and where you handle it?
|
|
|
|
|
econy wrote: But I found it seems the threading.timer() produces many threads,like each cycle
it use a new thread to read.
From the documentation:System.Threading.Timer is a simple, lightweight timer that uses callback methods and is served by thread pool threads. It is not recommended for use with Windows Forms, because its callbacks do not occur on the user interface thread.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
I got error message while installing an VB.NET applicaiton -
"Cannot Start Application
An error has occurred writing to the hard disk. Check if there is enough available space on the disk. Contact the applicaitonh vendor..."
In the Detail, it has -
"ERROR SUMMARY
Below is a summary of the errors, details of these errors are listed later in the log.
* Activation of C:\amldoc1\VB 2003\Project\FTT\publish\NetCommFieldTestTool.application resulted in exception. Following failure messages were detected:
+ Downloading file:///C:/amldoc1/VB 2003/Project/FTT/publish/Application Files/NetCommFieldTestTool_1_0_0_0/Converter.netmodule.deploy did not succeed.
+ The file 'C:\Users\aoum\AppData\Local\Temp\Deployment\K4ZJZGMC.N2C\5045Z1V0.DDV\Converter.netmodule' already exists."
I have tried the solution posted on your site --> Publish - Application Files and select "Include" for all dll files.... still the same error.
Any idea or suggestion?
Thanks for your help!!
|
|
|
|
|
You try clearing out your temporary files before installing?
|
|
|
|
|
yes, I cleared the temp files under Windows\Temp and Users\(myid)\AppData\Local\Temp... still the same error...
There's "install.log" in then Temp\VSD666.tmp -
"
The following properties have been set:
Property: [AdminUser] = true {boolean}
Property: [InstallMode] = HomeSite {string}
Property: [ProcessorArchitecture] = AMD64 {string}
Property: [VersionNT] = 6.1.1 {version}
Running checks for package 'Windows Installer 3.1', phase BuildList
The following properties have been set for package 'Windows Installer 3.1':
Running checks for command 'WindowsInstaller3_1\WindowsInstaller-KB893803-v2-x86.exe'
Result of running operator 'VersionGreaterThanOrEqualTo' on property 'VersionMsi' and value '3.1': true
Result of checks for command 'WindowsInstaller3_1\WindowsInstaller-KB893803-v2-x86.exe' is 'Bypass'
'Windows Installer 3.1' RunCheck result: No Install Needed
Running checks for package '.NET Framework 3.5 SP1', phase BuildList
Reading value 'SP' of registry key 'HKLM\Software\Microsoft\NET Framework Setup\NDP\v3.5'
Read integer value 1
Setting value '1 {int}' for property 'DotNet35SP'
The following properties have been set for package '.NET Framework 3.5 SP1':
Property: [DotNet35SP] = 1 {int}
Running checks for command 'DotNetFX35SP1\dotNetFx35setup.exe'
Result of running operator 'ValueGreaterThanEqualTo' on property 'DotNet35SP' and value '1': true
Result of checks for command 'DotNetFX35SP1\dotNetFx35setup.exe' is 'Bypass'
'.NET Framework 3.5 SP1' RunCheck result: No Install Needed
Launching Application.
Application appears to be an application manifest
Launching application manifest via dfshim "
Any idea?
Thanks for your help!!
|
|
|
|