|
Hi ,
I have question about .NET assemblies , say I have a Assembly 'X' and that conatins class 'xx' and my two different seperate applications uses this assembly , say Appl'A' and App'B' .
Then is it possible that I could share the object of class 'xx' in two applications ?
Like App'A' initiate object of class 'xx' and later on when App'B' comes, somehow I could tell that application that object of class 'xx' is already created and use that same object which App'A' has created.
Is it possible to do ?
I will really apprecaite if you could help me out here
Thanks,
ZINK
ZINK
|
|
|
|
|
You can accomplish this using .NET remoting: if AppA created the object, it would publish the object using .NET remoting's RemotingServices.Marshal(...) method. Then, AppB can connect to this same object using RemotingServices.Connect(...) .
|
|
|
|
|
I have developed a glossary application whereby users can insert terms into the glossary. I have a function to check for duplicate word entries. Unfortunately there is a minor flaw here in the fact that a user can enter the same word with a leading space and it will be entered in the db as a new word. I.E. The Word and The Word[space] are to different entries. Is there a way to delete leading white spaces after/before a character string. Also I do not wish to delete words with spaces in between the words (i.e. The[space]Word). All suggestions welcome and future thanks to all that reply.
|
|
|
|
|
Have a look at Trim function an d its overloads of string class
|
|
|
|
|
Use the Trim() method of the string object, e.g.:
string textToEnter = " Citizen Kane";
textToEnter = textToEnter.Trim(); // it is now "Citizen Kane"
|
|
|
|
|
I'm running a service which puts out a log file as well as Debug.Trace.Writeline messages. When I'm on the server (as an administrator), run DBGVIEW.EXE, and then start the service I never see any trace messages.
Does anyone know what needs to be done so that trace messages can be seen??? Unfortunately, the problem I'm trying to debug on the server is the service either creating the new log or copying the old one to a backup directory....so I'm dying on my only alternative to viewing my tracing.
|
|
|
|
|
Hello,
I am trying to read a xml file using Memorystream, after 800 files i do get a exception
"Exception of type 'System.OutOfMemoryException' was thrown.
This is the code snippet, can any one pls suggest how to get rid of this?
<br />
public virtual bool TransformXML2( string strTempXml, ref string strTransformedXml )<br />
{<br />
bool bSuccess = true;<br />
if (m_strTransformFile.Length == 0)<br />
{<br />
PIUUtilitiesMgr.PIUMessage(PIUUtilitiesMgr.GetResourceString("MISSING_XSLT_FILE_NAME"), PIUUtilitiesMgr.GetResourceString("PERSONNEL_IMPORT_UTILITY"), MessageBoxButtons.OK);<br />
return false;<br />
}<br />
<br />
try<br />
{<br />
<br />
System.IO.MemoryStream streamTempData = new System.IO.MemoryStream();<br />
PIUUtilitiesMgr.FromStringToMemoryStream(streamTempData, strTempXml);<br />
string outText = PIUUtilitiesMgr.MemoryStreamToString(streamTempData);<br />
<br />
PIUUtilitiesMgr.WriteToFileForDebuggingPurpose("TempUserList.xml", outText, true);<br />
<br />
System.IO.MemoryStream streamTransformedData = new System.IO.MemoryStream();<br />
streamTempData.Position = 0;<br />
<br />
<br />
XmlReader reader = XmlReader.Create(streamTempData);<br />
XslCompiledTransform xslTransform = new XslCompiledTransform(true);<br />
<br />
XsltSettings settings = new XsltSettings(true, true);<br />
xslTransform.Load(m_strTransformFile, settings, new XmlUrlResolver());<br />
<br />
xslTransform.Transform(reader, null, streamTransformedData);<br />
<br />
streamTransformedData.Position = 0;<br />
<br />
strTransformedXml = PIUUtilitiesMgr.MemoryStreamToString(streamTransformedData);<br />
<br />
strTransformedXml = strTransformedXml.Remove(0, 1);<br />
streamTransformedData.Close();<br />
streamTransformedData.Dispose();<br />
streamTempData.Close();<br />
streamTempData.Dispose();<br />
<br />
<br />
<br />
<br />
if (piuInfo.DebugMode)<br />
{<br />
lock (this)<br />
{<br />
PIUUtilitiesMgr.WriteToFileForDe1buggingPurpose("TransformedUserList.xml", strTransformedXml, true);<br />
}<br />
}<br />
<br />
}<br />
<br />
|
|
|
|
|
You may want to watch your system with conditional breakpoints (like every 200 loops) and see if you are experiencing any memory leaks. In the earlier framework, the XML entities in the framework had a bad habit of leaking resources...ending in a memory not found condition.
In the 2.0 framework it was supposed to be fixed but I don't remember looking into it at all. So look into it. If you are experiencing issues then you've got to talk to your microsoft consulting rep and see what they can do to help you.
|
|
|
|
|
Hey all!
First off, a little background. I currently live in the UAE where the internet here is monitored and sites are blocked by our ISP's proxy server. Even applications like Skype are blocked here. So I decided that I want to try coding a little application that me and my friends would find useful for bypassing this proxy server. My plan is as follows:
(1) I already have a dedicated server in the US and I connect to it by remote desktop anytime I need to download anything that's blocked. I intend to use this server to re-route traffic to my computer.
(2) With the above in mind, I want to develop a client side proxy application. It would be running in the background, and the user would configure his IE or Firefox to the local computer's IP and a port number and start sending all requests through the client proxy app.
(3) The client proxy application would encrypt the request and send it to the server application sitting on my server in the US.
(4) The server would decrypt the request and fetch the pages and images of the sites that are blocked here in the UAE. After that, it would encrypt the result and send it back to the client which, in turn, would pass it off to the browser.
I hope all that made sense. Now, I am kinda new to network programming, so all I need is a point in the right direction to start me off. I'm also trying to get this to work for any application that connects to the net like Skype.
Thanks for any help guys! And feel free to suggest any other better ways I can go about solving my dillemma.
Cheers!
|
|
|
|
|
1) You want someone to help you gain access to sites banned by the govt?
2) Leaving the legality issue over here, why are you trying to write your own proxy application when you can let your server in US act as a proxy server and your browser/software use those proxy settings?
3) According to the laws of UAE, VOIP is illegal(I worked over there for a year). I last heard they are coming up with some kind of solution for the VOIP and you should be trying to use the legal way and not get into trouble.
This is the 3rd time this month a person who had created his/her account years ago(5 years in your case) comes up with a first posting which would have to be something stupid/illegal
|
|
|
|
|
Hello everyone,
I am using a DataGridView to display the entire data stored in a remote Database server. I am using the following code for populating the dataGridView controller.
OdbcAd = new System.Data.Odbc.OdbcDataAdapter("SELECT * FROM " + SelectedTableName + ";", OdbcCon);<br />
<br />
DataSet myds = new DataSet();<br />
<br />
OdbcAd.Fill(myds, SelectedTableName);<br />
<br />
dataGridView2.DataSource = myds.Tables[SelectedTableName];
I would like to have the Dataset continue to be available even after been disconnected from the remote database server.
Can someone tell me how this can be done?
Thank you very much and have a great day.
Khoramdin
|
|
|
|
|
What do you mean by saying available dataset? After disconnecting you dataset holds the data that was fetched when Fill method was called.
|
|
|
|
|
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.
|
|
|
|
|