|
I need to ping a remote host using its IP address through a wireless network (in C#). Now i found many Ping classes here in CodeProject. But i am not sure if i can use those classes for wireless network. So you can see i am more worried about wireless network than ping, because i have not much idea about it.
Please help to clear my confusion cause i need this badly for a project... thanks for your patience ...
Chayan
|
|
|
|
|
From the point of view of performing ping tests, it is the same regardless of whether the network device is wireless or hardwired
The ping classes you have found should work, what problems have you found? Can you test app ping a hardwired device?
|
|
|
|
|
Whether the network is wired or is wireless, it doesn't make any difference to a ICMP packet. It's still the same TCP/IP, no matter what the underlying physical layer is.
|
|
|
|
|
Hello all,
I need some advice relating to managing memory and resources within the .NET Framework. Basically I have an application that from time to time will need to perform the following actions on 200mb+ strings:
App A
1) Compress (using SharpZipLib)
2) Break the compressed byte[] into and array of byte[] chunks
3) Push each chunk onto a WebService
App B
1) Receive chunks from WebService
2) Reconstruct chunks into a single byte[]
2) Uncompress
As you can imagine this takes massive amounts of resources, infact my first stab (for only a 25mb string) resulted in peak memory usage around the 300mb mark.
After some research I found that I can force the GC to collect unused objects, and therefore littered the code with this at relevant points. This resulted in a memory usage peak of around 200mb, better but still not perfect.
So now I am looking for alternatives. At the moment I am mainly looking at doing all the work in an AppDomain and then once completed unload and kill this. However I would appreciate any input on alternative designs.
Whilst I release this probably a bit much for a simple question, the following is the code I currently use. While this works (for small amounts of data), the design really isnt scaleable enough to handle large inputs (200mb+)
...
...
object[] outData = DeflateAndChunk(data);
...
...
string reconstructedData = DechunkAndInflate(outData);
...
...
private static byte[] DeChunkData(object[] baseData)
{
int returnLength = 0;
foreach(byte[] ba in baseData)
{
returnLength += ba.Length;
}
byte[] readBuffer = new byte[returnLength];
using (Stream outStream = new MemoryStream(readBuffer))
{
for (int loop=0; loop<baseData.Length; loop++)
{
byte[] dataChunk = (byte[])baseData[loop];
outStream.Write(dataChunk, 0, dataChunk.Length);
baseData[loop] = null;
}
outStream.Flush();
outStream.Close();
}
GC.Collect();
return readBuffer;
}
private static object[] ChunkData(byte[] baseData, int chunkSize)
{
int returnArraySize = baseData.Length / chunkSize;
int baseDataModulus = baseData.Length % chunkSize;
if (baseDataModulus > 0)
{
returnArraySize++;
}
object[] returnData = new object[returnArraySize];
using (Stream baseDataStream = new MemoryStream(baseData))
{
baseData = null;
for (int loop=0;loop < returnArraySize; loop++)
{
int workingChunkSize = chunkSize;
if (loop == returnArraySize)
{
workingChunkSize = baseDataModulus;
}
byte[] buffer = new byte[workingChunkSize];
baseDataStream.Read(buffer, 0, workingChunkSize);
returnData[loop] = buffer;
}
baseDataStream.Flush();
baseDataStream.Close();
}
GC.Collect();
return returnData;
}
public static object[] DeflateAndChunk(string inputMessage)
{
long adler32Checksum = 0;
byte[] compressedData = CompressData(inputMessage, out adler32Checksum);
inputMessage = null;
int chunkSize = 1000;
object[] chunkedData = ChunkData(compressedData, chunkSize);
return chunkedData;
}
public static string DechunkAndInflate(object[] inputData)
{
byte[] deChunkedData = DeChunkData(inputData);
byte[] inflatedData = UnCompressData(deChunkedData);
deChunkedData = null;
return System.Text.ASCIIEncoding.ASCII.GetString(inflatedData);
}
private static byte[] CompressData(string message, out long adler32Checksum)
{
byte[] returnData = null;
using (Stream inStream = new MemoryStream(System.Text.ASCIIEncoding.ASCII.GetBytes(message)))
{
message = null;
using (Stream outStream = new MemoryStream())
using (ZipStreams.DeflaterOutputStream deflatorStream = new ZipStreams.DeflaterOutputStream(outStream,
new ZipCompression.Deflater(ZipCompression.Deflater.BEST_SPEED)))
{
....
....
}
}
BaseCompression.Checksums.Adler32 ad32 = new BaseCompression.Checksums.Adler32();
ad32.Update(returnData);
adler32Checksum = ad32.Value;
GC.Collect();
return returnData;
}
private static byte[] UnCompressData(byte[] deflatedData)
{
byte[] returnData = null;
using (Stream inStream = new MemoryStream(deflatedData))
{
deflatedData = null;
using (MemoryStream outStream = new MemoryStream())
using (ZipStreams.InflaterInputStream inflatorStream = new ZipStreams.InflaterInputStream(inStream))
{
....
....
}
}
GC.Collect();
return returnData;
}
-- modified at 13:38 Wednesday 9th May, 2007
|
|
|
|
|
Hi,
some thoughts:
1.
why compress all the data at once, and then go through the trouble of chunking
it ? cant you compress part of the data (say 10 MB) and send it, then the
next part, etc. This avoids allocating and filling the big byte[] all together.
2.
to operate on part of a byte[] the API should provide a method that accepts
said array, a start index and a length, so you dont need to copy to get
the subset of the array. Most .NET classes have this.
3.
I advice against calling GC directly. The GC works fine, it collects when there
is a need to collect, and AFAIK it uses adaptive algorithms, which will
get disturbed by calling it explicitly.
|
|
|
|
|
After doing a little research on GC collect I have come to the same conclusion as the one you posted, hence the idea of using it doesnt really sit very comfortably with me.
Unfortunatly I have to compress and chunk, as the bigger bigger picture is that the send is done via a 3rd party intermediary that has defined this model. Unfortunately I do not control this and therefore I need to work with it
|
|
|
|
|
Can the compressing be done without loading it all into memory? For example, the System.IO.Compression APIs let you do this by writing to a stream, which is compressed on its own. The stream should point to a file on disk, thus you never have to load the big file into memory, instead the hard disk holds it all. As for sending the chunks, again, just read pieces of the compressed file using the standard System.IO.FileStream APIs.
|
|
|
|
|
Unfortunately I am stuck with .NET 1.1 so the compression libraries arent available for this
|
|
|
|
|
MrEyes wrote: After doing a little research on GC collect I have come to the same conclusion as the one you posted, hence the idea of using it doesnt really sit very comfortably with me.
As Luc pointed out, you really should not be calling GC.Collect yourself. The issue here is that every time the GC starts a collection cycle, it actually freezes the main thread of your application so it can determine which objects are still being referenced. By calling GC.Collect yourself and forcing a collection cycle, you are increasing the amount of time your application will spend in garbage collection, thereby ultimately decreasing your performance.
-----------------------------
In just two days, tomorrow will be yesterday.
|
|
|
|
|
Since strings are immutable in C#, every time you make a change to one you are creating a new string object. It doesn't look like you are doing much actual string manipulation beyond converting it to a byte array, but if you are you may want to look at StringBuilder[^].
I don't think using a separate AppDomain is really going to buy you much as you will then incurr the overhead of loading and unloading the AppDomain.
Finally, how are you determing your memory usage? The information shown by task manager is not accurate for .NET applications and should not be used. You should be looking at the .NET related performance counters in perfmon.
-----------------------------
In just two days, tomorrow will be yesterday.
|
|
|
|
|
Well I have to admit I have been monitoring memory usage via task manager so I will have a look at perfmon.
That being said, on large files (>200mb) the application eventually throws an out of memory exeception, which regardless of the monitoring mechanism is, how can a put it, catastrophic
|
|
|
|
|
Good People,
I have a data grid and I am trying to get a value from a cell. When I try to dereference the cell (i.e. DataGrid1[3,4]) it simply returns the coordinates (i.e. something similar to "Column 3, Row 4"). Any ideas or help you can provide would be great.
Thanks,
BP
|
|
|
|
|
u can access cell value by writing sth. like following
datagrid1.rows[i].itemarray(i).text
where itemarray represents the columns
|
|
|
|
|
I created an array list and added items to it.
When i search for items, i use the Enumerator.
When i find some items, i actually want to either remove or update the values. How would i do that if i am in an Enumerator loop
like
myEnumerator.Reset();
while (myEnumerator.MoveNext())
{
//found the item
//need to update the item, or remove
}
|
|
|
|
|
You will not be allowed to delete an item in an enumarator. You will have to loop through an instance of the arraylist and delete the item in the list
foreach (string s in new ArrayList(alData))<br />
{<br />
if (s == strSearchData)<br />
alData.Remove(s);<br />
}
|
|
|
|
|
Thanks,
how would i replace an element in the list... i do not see a function to replace in the array list.
|
|
|
|
|
foreach (string s in new ArrayList(alData))
{
if (s == strSearchData)
alData.Remove(s);
if (s == strFindData)
alData[alData.IndexOf(s)] = strReplaceData;
}
|
|
|
|
|
One thing you should watch out for is that changing the size of the list during a foreach() call will throw an exception.
So make sure that you don't add or remove items during enumeration. Find the items you want to operate on, save references to them (or their indices) and call the appropriate methods after the loop finishes.
|
|
|
|
|
I placed a gif file in my form,But its not animating
how can i do this?
My small attempt...
|
|
|
|
|
|
I have a gif file, can i place that in grid? i want to see the animation also
i tried with picturebox but no effect
My small attempt...
|
|
|
|
|
Greets all
Can anyone tell me how to apply the SeDenyInteractiveLogonRight right to an account in C#, preferably using the DirectoryEntry class?
Thanks
ccitt
|
|
|
|
|
Hello. I'm having a problem with Remoting.
I have remotable object that has a list of messages (arraylist with strings). That class is in a DLL file.
I have an application that uses that class. In some parts of the code, I add messages to the list.
Finally, I have another application where I want to show the messages. I receive the message using remoting, but the object comes without any message. The list is empty.
What can be happening?
Regards,
Diego F.
|
|
|
|
|
Hi,
I want my application to process multiple files, which it shall receive via the Windows-Explorer context menu entry "Open with...". I checked the command-line arguments, but the string[] has always just a length of 1 and string[0] only contains the first of all selected filenames.
How can I get all filenames which were selected when "Open with..." was clicked?
Thanks in advance,
Alex
|
|
|
|
|
To go more into detail: Am I right that I have to look for the selected filenames in the command line parameters?
Hasn´t anybody an idea? I don´t think that I am the only one who wants to receive multiple files using command line parameters...
|
|
|
|