|
I think this will do it.
DirectoryInfo d;
d.Delete(true);
|
|
|
|
|
Which directory will this code delete ?
|
|
|
|
|
There is an overloaded Delete method that takes a boolean parameter 'recursive' to specify that you want the delete operation to be recursive, that is, to delete all subdirectories, files, etc. in the specified path.
This code will do the trick.
Directory.Delete("some_file_path", true);
|
|
|
|
|
Hello,
how can i work with my JS-Objects, which i get over invoking JS in the WebBrowser-Control in my C#-Application? Is there any serializer? I get something like a "DOM-OBJECT" back from JavaScript, but can't work with it. So is there any possibility for example putting the Object into a string/xml-file put this through my invoked script and deserialize that xml-file or string into c#-classes?
Has somebody experience in doing that or working with that objects?
Thanks
|
|
|
|
|
Use the CreateJsonReader and CreateJsonWriter methods of the JsonReaderWriterFactory class to map JSON from / to XML.
|
|
|
|
|
Hello,
and how to use it? Because when i doing HtmlDocument.InovkeScript(...) i get as a return value a "object"... and if i try out which type it is i get "DOM-Object" or "COM-Object" (i'm not sure now), so how do i use this object which i get back in this JsonReader? Because in tutorials for this JsonReaderWriterFactory everyone uses some XmlDocuments...
Thanks
|
|
|
|
|
JSON objects consist of "name / value" pair elements.
The System.Xml.XmlDictionaryReader (and not "XmlDocuments") that you get back from the Factory consists of "name / value" pairs.
You use the Factory to read the JSON object as a "stream" and get back a XML reader which you then read using the .Read() method. Each "read" will get you a node with a Name, Value, NodeType, etc. Sometimes the Value contains nothing and you need to use one of the "Node.Readxxx" methods (e.g. ReadString()).
If you don't know what's in the JSON object, you're first go-around would be to simply dump everything for each node.
|
|
|
|
|
I am working with an application that has a background worker thread.
Passing infroamtion back is easy by using ReportProgress .
I can cancel the thread but is there a simple way to make calls to it to pass data? I have looked at message queues but it looks like overkill.
Recommendations?
Thanks.
[Update] System.Collections.Queue will do what I need plus it has a Synchronize method for thread safety.
modified on Friday, November 27, 2009 7:01 PM
|
|
|
|
|
yetch - if a noob had asked this question I'd have said - 'needs more design' - I think your options are a shared & thread-safe queue or similar or message queues Elaine - while it may 'look like overkill' when you're dealing with threads etc, its the tendency to cut-corners that brings people undone with locking etc
just my 0.02c worth
'g'
|
|
|
|
|
Trollslayer wrote: Passing infroamtion back is easy by using ReportProgress
That's correct for GUI output, for anything else communication with another thread needs one of many things (shared objects with locks, messages, queues, etc), the best pick very much depends on what kind of app it is, what kind of threading effects you have in mind. So if you want specific advice, tell us a lot more!
Luc Pattyn [Forum Guidelines] [My Articles]
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
|
|
|
|
|
OK, fair comment
The project is for running script based tests on embedded systems which will have a GUI for control and logging, the script engine itself and optional lower layers for communications.
Communication between layers will be low bandwidth since msot of the time the system will be waiting for response from the target system.
Also, I will need the option to run multiple instances.
The test scripts will be a plain text form so testers won't have to worry about programming and doing a load of damage.
Does that help?
Elaine
|
|
|
|
|
Hi Elaine,
no the situation isn't clear yet. I have no idea how long a test job lasts, and whether you want to change parameters in the middle of a test, etc.
I'll try to provide a general answer:
1. if jobs (units of work that will be executed sequentially) don't need parameter changes while running, either use a new BGW for each job, or create a queue (with a lock) where the main thread produces jobs and the BGW executes (i.e. consumes) jobs. With a queue, the BGW would have a main loop which dequeues a job and blocks when none available.
BTW: a queue can be implemented in many ways, e.g. by using the System.Collections.Queue class, the System.Collections.Generic.Queue<T> class, or something you build yourself probably on top of a List<T>
suggestion: carefully read the MSDN remarks on the queue you choose (thread safety!).
2. if a running job needs a simple parameter change, just change it (assuming no synchronization is necessary, i.e. the parameter is allowed to change at all times). If the parameter cannot be read in one CPU instruction, or if it should not be changed at random times, or if there are several parameters that need to be consistent, I would probably recommend an extra class:
2a. as a minimum a little Parameters class, so the producer can create a new instance, insert the new set of values, then have the consumer update its Parameters reference in a cooperative way (e.g. at the top of its execution loop).
2b. a more structured approach would take a Job class that hides the BGW, and provides properties for all parameters, so it also can hide your consistency stuff.
Example in pseudo-code (not quite safe):
class Job {
Parms initialParms;
Parms runningParms;
Job(Parms parms) {
initialParms=parms;
}
Run() {
runningParms=initialParms;
runPart1();
runningParms=initialParms;
runPart2();
runningParms=initialParms;
runPart3();
}
ParmType1 Parm1 {set {initialParms.Parm1=value;}}
ParmType2 Parm2 {set {initialParms.Parm2=value;}}
}
struct Parms {
ParmType1 Parm1;
ParmType2 Parm2;
}
The example isn't safe: you could be modifying Parm1 while the BGW is executing runningParms=initialParms; resulting in inconsistencies. So you need to provide some safety measure. A possible way would be:
class Job {
ManualResetEvent MREproducer;
ManualResetEvent MREconsumer;
Parms initialParms;
Parms runningParms;
Job(Parms parms) {
initialParms=parms;
MREproducer=new ManualResetEvent(true);
MREconsumer=new ManualResetEvent(false);
}
Run() {
updateParms();
runPart1();
updateParms();
runPart2();
updateParms();
runPart3();
}
updateParms() {
MREproducer.WaitOne();
runningParms=initialParms;
}
ParmType1 Parm1 {set {MREconsumer.WaitOne(); initialParms.Parm1=value;}}
ParmType2 Parm2 {set {MREconsumer.WaitOne(); initialParms.Parm2=value;}}
BeginParmChanges() { Clear(MREproducer); Set(MREconsumer);}
EndParmChanges() { Clear(MREconsumer); Set(MREproducer);}
}
struct Parms {
ParmType1 Parm1;
ParmType2 Parm2;
}
remark: to hide the BGW inside Job, create it in the constructor, and turn Run() into a DoWork() handler.
Luc Pattyn [Forum Guidelines] [My Articles]
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
|
|
|
|
|
Thanks Luc.
I won't be changing parameters 'on the fly' but will need to stop, pause and continue.
It may be necassary in the future to inject a script when the main script is paused.
System.Collections.Queue looks a good candidate and has a Synchronized method for thread safety.
Elaine
|
|
|
|
|
|
Thanks Daniel.
My application is simple enough I can use the first soluttion in this case (I hope!).
I have bookmarked both of these and now have a separate favourites folder called "Threading".
|
|
|
|
|
C# vs2008
Im building an application that needs to know the distance between 2 postcodes.
Are there any free web services or something with google I could use?
- Yes I know you can go onto google maps and find this out but I want the ability to do it in the back ground and display a cost for travel figure on the web form.
Thanks,
Chas
|
|
|
|
|
Google also offers a free API for access to their data. While it is oriented toward displaying maps for your customers, it may also be able to provide just mileage data - I haven't checked. One thing I find valuable about Google Maps is that the travel time estimates are usually very accurate, and those require detailed knowledge of typical road conditions, not just speed limits. This info may all be available as background data, but you'll have to search for it.
You could also check with ESRI - they offer a bunch of tools for GIS/GPS mapping. But you'll pay 'til you bleed for their products and services. They're probably the best game in town, but the price of admission is steep.
Another thought, and one I haven't researched at all... Have you looked at what the USPS has to offer? After all, they assign postcodes in the US, and provide shipping information for all manner of users in the US. Thay probably keep track of foreign addresses, as well, and may offer a webservice for consumers to use. It's worth a look, especially if any of your applications need US-centric information.
"A Journey of a Thousand Rest Stops Begins with a Single Movement"
|
|
|
|
|
In this test program i have a Main Form, Child Form and a Class
Main=frmMain
Child=frmChild
Class=cAction.
On then Main form i have one button(call mnuClientInfo), when click it, it calls "ShowClientInfo" function in cAction Class to load frmChild
In VB.net I would write something like this:
With my.forms.frmChild<br />
if .Visible then<br />
.Focus<br />
Else<br />
.MdiParent=my.forms.frmMain<br />
.Show<br />
End if<br />
End with
How do I do this in C#?
|
|
|
|
|
Hi,
There is no With construct in C#, so first modify your VB code to do what you want without using With , then you can port it directly to C#.
And if you want it done for you try one of the code converters[^] (no guarantee!).
Luc Pattyn [Forum Guidelines] [My Articles]
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
|
|
|
|
|
Hi
Yeah, It was more how to get a Class to show a child form in a Mdi Form
<br />
{<br />
if (frmClientInfo.Visible)<br />
{<br />
frmClientInfo.Focus();<br />
}<br />
else<br />
{<br />
frmClientInfo.MdiParent = frmMain;<br />
frmClientInfo.Show();<br />
}<br />
}<br />
} <br />
}
That didn't work
|
|
|
|
|
Hi
Yeah, it was to find out how to open a Child form from a class. I tried this:
{<br />
{<br />
if (frmClientInfo.Visible)<br />
{<br />
frmClientInfo.Focus();<br />
}<br />
else<br />
{<br />
frmClientInfo.MdiParent = frmMain;<br />
frmClientInfo.Show();<br />
}<br />
}<br />
} <br />
}
That didn't work....
|
|
|
|
|
Hi all,
Any idea about how could I return an array from the JavaScript code of a WebBrowser control? In another words: returning an array from a call of Document.InvokeScript .
Thank you.
Bogdan.
|
|
|
|
|
Use JavaScript's return statement.
|
|
|
|
|
Well, it seems that it didn't cross my mind...
Anyway, assuming that I do that, how should I interpret the answer on the .NET side? Chances are to get some COM wrappers of an interface I don't know.
That's what I'm looking for, the appropriate interface to communicate through.
Bogdan.
|
|
|
|
|
The return type for Document.InvokeScript is object . May be you should step through the code in the debugger and inspect what the return value contains.
|
|
|
|