|
I've always tought that when you create a new Item, you should always dispose it when you are finished with it, but when I create a:
Random rand = new Random();
The option to do rand.Dispose() does not exist.
Why is this? And what is the rule on disposeing?
Thanks
Thomas
|
|
|
|
|
Dispose generally exists to clean up unmanaged objects, the garbage collector deals with fully managed objects.
|
|
|
|
|
IMHO, System.Runtime.InteropServices.Marshal.ReleaseComObject(object o) is a better way to "tidy up" unmanaged objects in the pool...
Jeremy Kimball
I have traveled the gutters, lo these many days, with no signs of life. Well met.
-brianwelsch
|
|
|
|
|
not all objects of all class types need to be disposed.
only objects that should releasr some resources like open files , DB/Network connections, Handles.
this soes not apply to Random class.
|
|
|
|
|
Search the documentation for Finalization, Garbage Collection and Disposing. There are plenty of infos on this topic.
Also you could read this article[^] of MSDN magazine.
www.troschuetz.de
|
|
|
|
|
I just read a good debate over some uses of IDisposable interface over at Ian Griffith's blog[^] that you might find interesting.
#include "witty_sig.h"
|
|
|
|
|
Hi all,
In C#.NET, how to launch an slave application from a master application, then the master applicaton can close the slave master if the slave application is not needed anymore ?
And how to pass information between the two applications?
Thanks
|
|
|
|
|
FOr starting application you can use Proccess.Start() method. Fr passing parameter you can see StartInfo propoerty of this class. For closing it I think you have to use some win32 API , I don't remember exactly now which one. Other CPains may help you.
Mazy
"One who dives deep gets the pearls,the burning desire for realization brings the goal nearer." - Babuji
|
|
|
|
|
Use the static Process.Start methods to launch your slave application. You will need the path of the executable and can optionally specify arguments which will be passed to your application.
Both overloads of the Start method return a object of the Process class. Store it and call the Kill method of this instance when you want to shut down your slave application.
For passing of information between applications, there exist several ways. You could use a socket connection, Remoting or just send Windows messages. It depends on what you want to send, if the communication should be uni- or bidirectional and some other facts.
www.troschuetz.de
|
|
|
|
|
Calling Process.Kill like Stefan said is an option, but it's not a very good one. This terminates the process and leaves the OS to free handles. If you need your process to close these yourself for any reason, use Process.CloseMainWindow then Process.Close . See the method documentation for Process.Close for an example.
To communicate between the two applications, you should consider using .NET Remoting with a TcpChannel if they are both .NET applications. This is by far the easiest way for communications, despite the overhead of TCP (in .NET 2.0, they are adding an IpcChannel ). If they aren't, then there's a myriad of ways to do this from using RPC (you'll have to P/Invoke the necessary APIs in your .NET application) to global memory to shared pipes, etc.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
THX for the correction considering the Process.Kill method. I will remember that
www.troschuetz.de
|
|
|
|
|
I'd like to start a help-project in my VS.Net. The VS-Help states, that I have to start a new project an then follow the instructions of the New Project Wizzard.
But if I do so, there is no New Project Wizzart. How get I back to this wizzard?
Thanks
Ariadne
|
|
|
|
|
Just click on the File menu and select New->Project. There's your "wizard". From there you can create different project types. Some have wizards and some are just templates. In order for a Help project to show up, you need to download the VSHIK from http://msdn.microsoft.com/downloads[^].
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks Stewart!
but if I try to install VSHIK.exe I get
Visual Studio .NET must be installed to run this insallation package
But VS.NET is installed...
Did I something wrong?
|
|
|
|
|
Check the system requirements for the VSHIK. There are two different versions of Visual Studio .NET, mind you (2002 and 2003). If the VSHIK uses Windows Installer (IIRC, it does), you can create a transform (if you know how) that will install it for the other version of Visual Studio .NET. In most cases, this should work just fine.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks: it works
Ariadne
|
|
|
|
|
can anybody show me how to add checkboxes to DataGrid and how to know the items that is checked.
Rock Throught The Night
|
|
|
|
|
|
I have a class i made that is derived from a label. I was wondering how in the heck do you disable word wrap? I tried this.AutoSize=false; but that doesn't seem to effect anything.
I was looking for something like WordWrap but i don't see anything like. Is there a function i can call to dispable this? Cause what happens is the text on my label is sometimes longer than the label and instead of cutting it off it just makes the label height bigger so it can accomidate the length. Basically word wrapping it.
Thanks for the help
Win32newb
"Programming is like sex, make one mistake and you have to support it for a long time"
|
|
|
|
|
As usual, the solution comes down to the underlying Windows common control - the Static Control[^]. You can disable word wrap using the SS_LEFTNOWORDWRAP (0x000c) style. Tie it to a property like so:
public class MyLabel : Label
{
private bool wordWrap = true;
private const int SS_LEFTNOWORDWRAP = 0x000c;
protected override System.Windows.Forms.CreateParams CreateParams
{
get
{
System.Windows.Forms.CreateParams cp = base.CreateParams;
if (!wordWrap) cp.ClassStyle |= SS_LEFTNOWORDWRAP;
return cp;
}
}
[DefaultValue(true)]
public bool WordWrap
{
get { return wordWrap; }
set
{
if (wordWrap != value)
{
wordWrap = value;
RecreateHandle();
}
}
}
}
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi all,
I want to add my own functionality (Some Menu Item) to VC6.0 IDE. Can we do that ?? If yes, how to do that? If anybody got some clue, just advise.
Thanks and Regards,
Satya.
Never never never give up.
|
|
|
|
|
SatyaDY wrote:
If anybody got some clue
First CLUE: Post in the correct forum
SatyaDY wrote:
just advise
Advice: Post in the correct forum
Yes, I program in VB6, but only because I use it to fill my addiction to having a dry place to sleep and food to eat!
|
|
|
|
|
1. how i will know which version of .net framework that is there in my machine.
2. how i will locate through programming.
Please feel free to contact.
Sreejith S S Nair - Bangalore
|
|
|
|
|
sreejith ss nair wrote:
1. how i will know which version of .net framework that is there in my machine.
There's no excuse to not know what software is on your computer, unless network administrators are pushing out installations. Never blindly install anything on your machine. This is true for any machine and for any application.
You can figure it out many ways. The easiest is to browse to %WINDIR%\Microsoft.NET\Framework. The sub-directories in there will tell, so long as their full of files (newer frameworks install a few files into older directories, but it's noticably fewer files). v1.0.3705 corresponds to the .NET Framework 1.0. v1.1.4322 corresponds to the .NET Framework 1.1. You can also just open Add/Remove Programs from the Control Panel and look as well.
Programmatically, it's really quite easy. Read about the Environment.Version property in the .NET Framework SDK. The Version.Major and Version.Minor numbers should correspond to the .NET Framework version that you're running under.
Note that the assembly versions don't reflect this. .NET 1.0's assemblies versions are 1.0.3300.0, while the SP2 file versions are 1.0.3300.228. The .NET 1.1 assemblies are version 1.0.5500.0. I don't know why, but that's the facts. I will tell that Microsoft does change the file versions to reflect the service pack changes, but the assembly version remains unchanged so that code targeting that .NET version doesn't need to be recompiled or redirected. File versions are for informational purposes where assembly versions describe both the assembly as well as a type within that assembly. Different versions mean different assemblies or types.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi,
How do I create the IDataSourceLocator (hWnd) for my MSDASC.DataLinks object without first calling the PromptNew() method plus DialogResult.OK ??
I have a program where I want the user to be able to edit a connection string known (loaded) when the program starts. I want to be able to do something like this:
private ADODB._Connection m_AdoDbConn;
// then, create m_AdoDbConn without calling PromptNew() so I can do..
m_AdoDbConn.ConnectionString = sConnStrLoadedFromDisk;
object o = (object) m_AdoDbConn;
MSDASC.DataLinks oDlg = new MSDASC.DataLinksClass();
oDlg.PromptEdit(ref o);
---------------
TIA,
Matt
|
|
|
|