473,395 Members | 2,253 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Thread with timeout, pls help



Hi, I am kind of new in programming and I have a problem.
I am getting some values through SNMP and when I don't get an answer
from remote host, my refresh function keeps waiting. I cannot modify the
function because is from a .dll. I need some timeout thread who can stop
after 2 seconds if I don't get any answer from the remote host.

Here it is:

private string mib_read(string host, uint[] mib)
{
{
string val;
ManagerSession sess = new ManagerSession(host,"public");
ManagerItem mi = new ManagerItem(sess,mib);
try
{
logText("before [read] refresh...");
mi.Refresh(); //<-------------The crash !!! logText("after [read]
refresh...");
val=mi.Value.ToString();
}
catch (Exception e)
{
logText("Refresh Failed........."+e);
val="NULL";
}
return val;
}
}

Please help.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #1
2 2498
Hi,
It does depend of the lib functionality. Maybe it does provide a property
or a constructor overload where you can set the timeout.

If not you are pretty much without much else to do.

The only other possible solution I can think of is create a thread to do the
Refresh while the main thread sleep for two seconds, then check if the
worker thread is still blocked ( you may use a flag for this) and if it is
do accordingly.
cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Dan Pavel" <my**************@yahoo.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...


Hi, I am kind of new in programming and I have a problem.
I am getting some values through SNMP and when I don't get an answer
from remote host, my refresh function keeps waiting. I cannot modify the
function because is from a .dll. I need some timeout thread who can stop
after 2 seconds if I don't get any answer from the remote host.

Here it is:

private string mib_read(string host, uint[] mib)
{
{
string val;
ManagerSession sess = new ManagerSession(host,"public");
ManagerItem mi = new ManagerItem(sess,mib);
try
{
logText("before [read] refresh...");
mi.Refresh(); //<-------------The crash !!! logText("after [read]
refresh...");
val=mi.Value.ToString();
}
catch (Exception e)
{
logText("Refresh Failed........."+e);
val="NULL";
}
return val;
}
}

Please help.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 16 '05 #2
Hi,

There are 2 problems with this solution:
1. If I wait 2 seconds for every MIB read, my apllication will become
very slow.
2. I am not very good with threads, so if you can, give me a more
detailed solution.

I think that what I need is somehow to perform a check something like
that:

If the mi.Refresh() return a value within 2 seconds, continue to value
assign, else (if the 2 seconds passed) forgot the mi.Refresh value and
assign "NULL" to val.

Thanks in advance,
Dan

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Jacek Popławski | last post by:
Hello. I am going to write python script which will read python command from socket, run it and return some values back to socket. My problem is, that I need some timeout. I need to say for...
28
by: dcrespo | last post by:
Hi all, How can I get a raised exception from other thread that is in an imported module? For example: --------------- programA.py ---------------
2
by: GregM | last post by:
Hi First off I'm not using anything from Twisted. I just liked the subject line :) The folks of this list have been most helpful before and I'm hoping that you'll take pity on a the dazed and...
6
by: ll | last post by:
Hi, How to specify the timeout value(ms) for a thread? Thanks.
0
by: Johanna | last post by:
Hello, Thread was being aborted exception is thrown by my asp.net application. I hope someone could help me with this error that I get in windows 2003 server. This error has not occured with...
0
by: puff | last post by:
When interfacing to a COM object, is it possible to pump messages in a thread? I'm working on an application that automates IE and needs to monitor IE events (yes I know about Pamie). I'm able...
5
by: Alex A. | last post by:
I have this web application that runs for about 5 minutes doing to database processing, about 50% of the time I get the error message Thread was being aborted. I am looking for hint at where to...
1
by: Chrace | last post by:
Hi all, I have a problem with with Thread.Join( Timeout ) where the timeout never occurs. I basically need to make a connection to an AS400 box which works fine. Once in a blue moon the AS400...
3
by: yeye.yang | last post by:
hey everybody Does everybody can help me or give me some advise for the cross thread exception catch Here is what I want to do: I have 2 classes "Scenario" and "Step", which have a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.