|
There is no folder/directory stream in DNF. But you can write the entire folder in a binary file using BinaryWriter and Extract all the files from that binary file when require. All you need to think a file format. eg.
int - Number of Files
----For each file----
string - FilePath
int - FileLength
byte[FileLength] - Data
----------------------
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L
%^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2
W_AD`EPABIKRDFVS)EVLQK)JKQUFK[M`UKs*$GwU#QDXBER@CBN%
R0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-iTV.C\y<pjxsg-b$f4ia>
-----------------------------------------------
128 bit encrypted signature, crack if you can
|
|
|
|
|
Hi All,
I'm trying to find some info on watching for new drives being plugged into the system. The normal kind of drives like Firewire, USB drives, flash sticks, eSata etc.
The FileSystemWatcher seems to only support watching an existing drive. Would WMI be the place to go for this?
Cheers,
|
|
|
|
|
search CodeProject for WM_DEVICECHANGE
|
|
|
|
|
|
Hi,
I have a problem here, In a constructor class I am creating a synchronous socket which I use during this class is alive.
In the destructor of the class I want to Shutdown and Close the socket, but I get a very nice Exception: "ObjectDisposeException was handled" ...
How can I Shutdown and Close the socket when the object is destroyed?
Am I not suppose to shutdown or close the socket by myself?
Example:
~DDLBaseMsg()
{
if (Sender != null)
{
Sender.Shutdown(SocketShutdown.Both);
Sender.Close();
}
}
|
|
|
|
|
You should implement the IDisposable interface and call Dispose from the Finalizer. The code you currently have in the Finalizer should be moved to the Dispose method.
The Dispose method should detect if it is already disposed and not do so again. I suspect that the exception you got was because the Sender was already disposed, but you still had a reference to it.
|
|
|
|
|
Hi,
Ok, Thanks for the explanation of the IDisposable, however, I get the same error
The code is simple, I have a form which instantiate the socket owner class CBaseMsg in the constructor:
public partial class FrmMain : Form
{
CBaseMsg BaseMsg;
public FrmMain()
{
InitializeComponent();
BaseMsg = new CBaseMsg();
}
private void buttonTest_Click(object sender, EventArgs e)
{
BaseMsg.SendSomething("Test");
}
}
The class that instantiates the socket:
What I basically do is to call Dispose() from the Finalizer. I tried also to use the dispose alone, but if I put there a break point it seems that never runs.
As you can see I am not closing nor diposing the Sender instance before calling the dispose method or finalizer. The instances should be "alive" while the form exist.
Should I call dispose of the CBaseMsg from the Dispose of the FrmMain?
Another Question:
Should I really need to Shutdown() the socket? (Close() works just fine in the Finalizer and Dispose()...)
Maybe it is already automatic and I am just investing unnecessary time ...
class CBaseMsg : IDisposable
{
IPHostEntry ipHostInfo;
IPAddress ipAddress;
IPEndPoint remoteEP;
Socket Sender;
public CBaseMsg()
{
ipHostInfo = Dns.GetHostEntry("127.0.0.1");
ipAddress = ipHostInfo.AddressList[0];
remoteEP = new IPEndPoint(ipAddress, 55065);
Sender = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
Sender.ReceiveTimeout = 5000;
Sender.Connect(remoteEP);
}
~CBaseMsg()
{
Dispose();
}
public void Dispose()
{
if (Sender != null)
{
Sender.Shutdown(SocketShutdown.Both);
Sender.Close();
}
}
public void SendSomething(string Msg)
{
try
{
byte[] buffMsg = new byte[Msg.Length];
buffMsg = Encoding.ASCII.GetBytes(Msg);
int bytesSent = Sender.Send(buffMsg);
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
|
|
|
|
|
Going by some of your naming conventions I'm guessing you are coming from a C++/MFC background. That being the case you need to think about things a little differently. Well, I suspect you are, but the pendulum has swung too far the other way. You'll get what I mean in a moment.
If you have something that is disposable then you need to dispose of it rather than let the garbage handler deal with it. Just like you do in C++. This is because if it is disposable it will be holding on to resources (like a socket, file handle, GDI resource, etc.) that needs to be cleaned up as soon as you are finished with it rather than when the garbage collector gets around to it.
Finalizers are not run in any specific sequence and you cannot guarantee that the objects you reference haven't already been finalized. Basically, the CLR is clever enough to realise that if you are unreferenced, then everything you reference that isn't referenced else where is also unreferenced. It essentially chucks it into a big queue and processes it but doesn't care about order
Finalizers are really just a backstop in .NET to ensure that if the developer has forgotten to dispose of something the garbage collector can at least get a chance at dealing with it.
Since you only check for nullability on Sender may already have been closed. According to Socket.Shutdown documentation[^] the exception you are getting is raised if you attempt to shutdown a socket that is already closed.
Rather than call Shutdown and Close, you may just want to call Dispose on the socket object which will clean up the Socket for you and can be called multiple times quite safely. If the interface is implemented implicitly then you can just call Sender.Dispose() . If it is an explicity interface you'll have to use ((IDisposable)Sender).Dispose();
I hope this helps.
|
|
|
|
|
Thanks for the explanation, you are rigth I used to be a C++/MFC programmer.
I know a little about the so called garbage collector ...
Anyway, I am a bit scare about freeding resources, as you know in C++ all must be done by hand ... so I wanted to "freed" the socket,
So, one last question:
Would be better if I just do nothing at all? (I mean not call close nor shutdown anything)
I mean, maybe if I just close my form the C# would take care of disposing ... closing ... shutingdown ... etc, everything ...
or should I just call on Dispose() the Sender.Dispose() method ...
|
|
|
|
|
The general rule is that if a class implements the IDisposable interface then you are responsible for calling Dispose before allowing your object drift off into the abyss. If you reference classes as a field (member variable) your class that implement IDisposable then your class should also implement IDisposable to dispose of the objects you are referencing.
You can of course leave it all up to the CLR but then the garbage collector is non-deterministic so if you need the resource again you might not get it because it is still tied up waiting to be garbage collected. Even if you force a garbage collection it might not free up immediately.
|
|
|
|
|
ok, Thanks for the reply.
|
|
|
|
|
Good day good people,
Anyone know how I can, from within my application, access the windows Task Scheduler (on XP or Vista) and set my application to run at a specific point in the future.
I have an application that needs to process some data. When it has reached a certain point, it has to stop then launch itself again later (e.g. 12 or 48 hours later, etc...).
Thus far I've only found Task Scheduler code for office interop with C#. Any help or direction you can provide would be greatly appreciated.
Thanks in advance,
Blitz
|
|
|
|
|
|
Thank you. I will look into the information you provided.
Blitz
|
|
|
|
|
Hi,
Why dont you try to build a windows Service?
And setup the next execution in the app.config file or maybe in a database.
|
|
|
|
|
Thank you.
I have one question. What is a windows service? Also, can you point me to an example of it.
Thank you.
Blitz
|
|
|
|
|
|
I have a new installation of VS2008 after a PC Rebuild and "Startup" does not appear under: Tools|Options|Environment. It was there before the rebuild.
Any ideas why it is missing and how to get it to appear? In particular I want to get VS to "Load last loaded solution" at startup.
|
|
|
|
|
Forget it, couldn't see the wood for the trees.
|
|
|
|
|
He he he.
My other signature is a Porche.
|
|
|
|
|
Naruki wrote: My other signature is a Porche.
You should reevaluate your sig as it is "Porsche", I should know.
|
|
|
|
|
I can't afford the 's'.
A man applied for a job to paint someone's porch for $100. The owner pointed him to several cans of white paint stacked on a weathered wood deck and told him to get started while he went in to eat lunch.
When the owner finished he went out to find the man snoozing on a rocking chair. Angrily he demanded to know why the man wasn't painting.
"I finished about twenty minutes ago. By the way, that's not a Porch, it's a BMW."
My other signature is a Porche.
|
|
|
|
|
Naruki wrote: A man applied for a job to paint someone's porch for $100.
On old one but .....
Here's $10 for the 's'.
|
|
|
|
|
Hi! I have to read a file and do some operations to it. The contents of the file are words - it is like a dictionary (over 10 000 words, later over 80 000). Each word must be read and compared to others. Which is the best way of accessing the data (and the fastest):
1) Read the whole file and add the lines to an ArrayList, after that the stream is disposed. Then do whatever I want to the lines.
OR
2) Open the stream and read each line and do whatever I want to it. During all the time the stream is opened!
Also I want to report progress.
1) With the the ArrayList:
int progress = 0;<br />
for (int i = 0; i < rawLines.Count; i++)<br />
{<br />
line = rawLines[i] as string;<br />
if ((i / rawLines.Count) * 100 > progress)<br />
{<br />
progress = (i / rawLines.Count) * 100;
Console.Title = progress.ToString() + "%";<br />
}<br />
}
2) With the stream:
int progress = 0;<br />
int rawProgress;<br />
while ((line = reader.ReadLine()) != null)<br />
{<br />
rawProgress = (int)((reader.BaseStream.Position / reader.BaseStream.Length) * 100);<br />
if (rawProgress > progress)<br />
{<br />
progress = rawProgress;
Console.Title = progress.ToString() + "%";<br />
}<br />
}
But! Both ways don't seem to work. With the stream, the value of reader.BaseStream.Position is always 1024. In the other case the value of i increases but the percentage in the console's title does not change?!
Still learning...
|
|
|
|
|
Use BackGroundWorker class
http://msdn.microsoft.com/en-us/library/system.componentmodel.backgroundworker.aspx
|
|
|
|