.NET Framework - timeout functionality

Asked By Fran
30-Jul-07 03:10 PM
Hi,

Is there a timeout facility when doing commands like get-wmiobject.
Sometimes when running scripts on hosts, I want it to timeout after 10
seconds.  I'm looking for something similar to the "expect" timeout.

Thanks in advance,
WMIObject
(1)
TotalMilliSeconds
(1)
Directory
(1)
Siddaway
(1)
Belgium
(1)
Logicaldisk
(1)
Otherwize
(1)
Exitafter
(1)
  Rich replied...
30-Jul-07 03:18 PM
Get-WMIObject doesn't have a timeout facility.  I am not aware of a timeout
facility within PowerShell
--
Richard Siddaway
Please note that all scripts are supplied "as is" and with no warranty
Blog: http://richardsiddaway.spaces.live.com/
PowerShell User Group: http://www.get-psuguk.org.uk
  Jean replied...
30-Jul-07 06:02 PM
You could play with new-timespan (and properties ... ,seconds,
milliseconds, ...)

This one stops after 5 seconds :

$exitafter=5000 #milliseconds
$start=(get-date)
$startms=(new-timespan $start).TotalMilliSeconds
do{
if(
(new-timespan $start).TotalMilliSeconds-$startm `
-ge `
$exitafter-$interval
)
{break} #or {exit}
###CODE###
}while($true)

Regards,

--
Jean - JMST
Belgium
  Jean replied...
30-Jul-07 06:13 PM
Sorry, this code instead :

$exitafter=5000 #milliseconds
$start=(get-date)
do{
if(
(new-timespan $start).TotalMilliSeconds `
-ge `
$exitafter
)
{break} #or {exit}
###CODE###
}while($true)


Regards,

--
Jean - JMST
Belgium
  Fran replied...
31-Jul-07 04:38 PM
For some reason, this still didn't work.  I replaced ###CODE### with "gwmi
win32_logicaldisk -computer test_cluster".  It still hangs forever.  This
host is the "non-active" cluster.

Thanks,
  Jean replied...
31-Jul-07 05:33 PM
I'd extracted the code from a bigger project, so what is needed is to
break (or exit) at the end of the code otherwize you go in an infinite
loop.

Here is an "example" :

#---8<---
$exitafter=10000
$dir=get-wmiobject win32_Directory
$start=get-date
do{
$dir|%{
$_.Name
if(
(new-timespan $start).TotalMilliSeconds `
-ge `
$exitafter
)
{'***10 SECONDS ELAPSED***';break}
}
'***SCRIPT END***'
break
}while($true)
#---8<---


But i'm not sure this could help you as if I understand well you need
an asynchronous stuff (or an event) and that, just now, I don't know
how to do (and even if it's possible or exists).

Regards,

--
Jean - JMST
Belgium
  Jean replied...
31-Jul-07 05:52 PM
Perhaps some informations here (i have not tested):

http://www.scriptinganswers.com/forum2/forum_posts.asp?TID=956

Regards,

--
Jean - JMST
Belgium
Create New Account
help
Create / remove directory .NET Framework Hello. I have problem with create and then remove directory on my site. It works like this. My page 1) create directory Directory.CreateDirectory(DirectoryPath); 2) put some files 3) Remove directory Directory.Delete(DirectoryPath, true); And I have problem here. For some strange reasons this directory because read only and locked. I can't even open this until reopen my visial studio. Why it happend? How I can create directory with full access and then remove it with all files and subfolders inside? ASP.NET
How do I check if a directory exists within another directory .NET Framework Hi, How do I check if a directory exists within another directory? For example C: / aaa C: / Aaa = true C: / aaa / C: / Aaa / bb = true C: / aaa bb / C: / aa / = false Thanks, Aine C# Discussions StartsWith (1) SubDir.ToLower (1) Aine (1) Directory (1) For these simple cases, how about: if (dir.ToLower().StartsWith (subDir.ToLower())) {} keywords: How, do, I, check, if, a, directory, exists, within, another, directory description: Hi, How do I check if a directory exists within another directory For example C: / aaa C: / Aaa = true C: / aaa / C: / Aaa
Enumerating a directory, FindFirst() / FindNext()? .NET Framework Is there a way to enumerate the files in a directory? The only method I see to get the files in a directory is Directory.GetFiles(). I don't want to get a list of all files in the directory but instead enumerate the files in a directory. The reason is that there are hundreds of thousands of files in the directory I'm processing and the Directory.GetFiles() method is taking quite a bit of time to build the list. Instead I
public class Lab { string name; public string Name { set { name = value; } get { return name; } } string directory; public string Directory { set { directory = value; } get { return directory; } } / / / <summary> / / / Constructor / / / < / summary> public Lab() { } / / / <summary> / / / Constructor / / / < / summary> / / / Lab Name / / / Directory Path public Lab(string name, string directory) { this.name = name; this directory = directory; } public bool Exists() { return new DirectoryInfo(directory).Exists; } } I then have another class which stores