|
Hello Giorgi,
Thanx for the reply. Maybe my choice of words have created confussion. This is exactly what's happening.
I get connected to the remote database and populate the DataGridView with the data available in remote database. The moment I disconnect from the remote database server, I lose my entire data presented in DataGridView.
I would like to get connected to the remote database and populate the DataGridview with the data from the database server and then disconnect from the server but having the data still available in my Windows Application.
Thank you very much for your help, mate.
Khoramdin
|
|
|
|
|
Hello Giorgi,
I am so stupid.... lol
After my last posting I scanned my codes once again and realised this line of code which was written long ago is clearing the DataGridView.
It is good that I left the comment on the code! he hehe hehehe
this.dataGridView2.DataSource = null; // To Clear the DataGridView "dataGridView2".
Thanx for your help, anyways.
Khoramdin
|
|
|
|
|
Hi,
Anybody konws how to translate this VB code to C# code
Private Declare Sub PickIconDlg Lib "Shell32" Alias "#62" (ByVal hwndOwner As Long, _
ByVal lpstrFile As String, ByVal nMaxFile As Long, lpdwIconIndex As Long)
Thanks.
|
|
|
|
|
Have a look at www.pinvoke.net
|
|
|
|
|
thank you very much
|
|
|
|
|
(via Instant C#)
[System.Runtime.InteropServices.DllImport("Shell32", EntryPoint="#62", ExactSpelling=true, CharSet=System.Runtime.InteropServices.CharSet.Ansi, SetLastError=true)]
private static extern void PickIconDlg(long hwndOwner, string lpstrFile, long nMaxFile, long lpdwIconIndex);
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
C++ to C# Converter: converts C++ to C#
Instant C++: converts C# to C++/CLI and VB to C++/CLI
Instant Python: converts C# to IronPython and VB to IronPython
|
|
|
|
|
Thanks
|
|
|
|
|
I've created a control inherited from PictureBox, same functionality, but just added support for fading the images.
I have ImageA and ImageB properties.
In ImageA puts a image just to fade it self, and when you put a image in ImageB, then ImageA fade to ImageB.
This works when I manually do that in design and in runtime, but when I use it in PictureBox array it doesn't work.
On the same form, I have two controls with fading stuff, and when I use that inherited PictureBox, those two controls doesn't work - it just hang.
I want to have a mouse over/out (no fading at that time) stuff when I over my mouse on those picture box arrays (this works with ordinary picture box control), and when I click on particular picture box, I want picture to fade it self, or to fade from one (ImageA) to another (ImageB) if ImageB isn't null.
I have a void which checks whether on clicked picture is drawn any images or not.
Thanks.
|
|
|
|
|
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;
}
|
|
|
|