Hmm. That sure is the easiest way, but it would severely degrade app responsiveness when Ping.Send() is awaiting a reply and possibly times out. Yes one can use an overload that offers a timeout parameter, however IMO there isn't a timeout value that is sufficiently long for Ping not to give false negatives, and at the same time sufficiently small for the app to remain fully responsive.
So for a periodic Ping to a constant address I would recommend using a separate Thread, with a forever loop holding Ping.Send() and a Thread.Sleep(); and then a simple bool variable could offer the latest state. Simple variables can safely be accessed across thread boundaries, no locking or other synchronization would be required.
Thanks Richard. That looks interesting. I had been considering async/await but am unfamiliar with it; also I'm not afraid of going all in with new Thread(). Your async approach seems like a lot of code...
All true. I set Thread.IsBackground true, and typically have a global public static bool AppIsExiting which I test in my forever loops. That takes care of most of the potential termination problems. Your approach is cleaner of course, mine dates back 20 years...
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
hi, does in c# exist a type of variable that is like pointers in c++?
I mean, in c++, if I use a pointer to a byte, I can add 1 to this pointer and, in this way, move it along all the array, in c#, is there a way to do a similar thing?
Do note that you need to specify unsafe for yoru code in order to use them, and you need to take precautions that the memory won't be moved by the GC while you are using the pointers. If you don't need 'em, don't use 'em: and that's "real need" not "I need this to be like my C++ code".
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
Hallo, I'm trying to extract images from pdf.
The problem is with some images that, in pdf, are with the attribute Predictor. I think that, with this attribute, the resultant bytes are to be decoded with png algorith, but I don't find it.
Another problem is with images that are with 8 bit indexed, in the pdf file I don't file the palette, as in other pdf files. Is there someone who is expert with pdf images? I hope my question is understandable. Thank you.
you seem to be peeking into the PDF file to extract what you need, and that is bound to give you surprises when several different PDF sources are involved.
There is another way to approach things, that may or may not meet your needs: using something like Ghostscript[^] you can get an image of a particular page of a PDF document (in any resolution you want), then operate on that.
The advantage is you don't need to deal with all the possible ways PDF stores/creates images; the disadvantages are (1) you only get the resolution you asked for and (2) if all you need is a picture you still have to locate it and extract it from the page image.
Ghostscript can be ran in a separate process; it takes parameters from its command line. It is one of the many programs that explain their parameters by running it with a /h, -h or -help argument in a command window.
Here is a method I once used, you would have to adapt it to your needs of course.
1. pageName is the name of the file that will be generated by ghostscript.
2. the generated file will be locked as long as the generated bitmap is alive.
3. you should Dispose() of the bitmap when you no longer need it.
If you have trouble with ghostscript, run it manually first, i.e. from inside a Command Prompt (you can copy/paste command lines into it) and look at what it tells you. Only when you're satisfied should you start using C# code and the Process class.
The easiest way to get the folder issues sorted is by putting the ghostscript exe and your C# exe in the same folder (say "Debug"); I expect ghostscript will then use paths relative to that ("Debug") folder.
NB: there is nothing to install about ghostscript, you can put the exe anywhere, as long as it can be found (e.g. because its folder is added to the PATH environment variable, or because it is in your "current directory"). Alternatively you can tell the Process class where it is, that is what my toolsFolder did.
Warning: if you specify a full or partial path for the output, you probably must make sure the folder exists before running ghostscript. And the output location must be writeable, so special folders such as C:\Program Files\ are a no-no.
I can't help you any further, it is all standard Windows behavior as far as I know.