To add to that, the DefaultTraceListener will output messages you pass to Trace or Debug to the output window when you're debugging your application in .NET. To write to files, the event log, or any custom targets you can use additional TraceListener implementations even at runtime (we use one for error logging in our app).
You're right, though, it is much better than the various TRACE macros, though - as Colin mentioned - a much better trace facility would be nice and is expected. To elaborate, every message you pass is passed to each TraceListener, regardless of whether or not they want to handle it (based on a TraceSwitch setting or other proprietary filtering). This can hamper performance.
Call me stupid, but after coding for 1 year now, I'm going to ask such a trivial question:
Object o; //Where does o fit in memory?
o = new Object(); //Now what? Instantiated? What's that?!
//Work on o somehow; then: o = some_fuction_that_returns_a_newly_created_object(); //Now?
How about the first o that was allocated? I used the same variable to point to two instances (or at least that's what I think) consequently. What happens to the first instance? What about if I want to destroy this o in memory because I simply don't need it anymore?!
Thank you, I appreciate your patience.
"A good friend, is like a good book: the inside is better than the cover..."
profoundwhispers wrote: Object o; //Where does o fit in memory?
It allocates enough memory on the stack for a reference (pointer) to the actual object (what ever it may eventually be)
profoundwhispers wrote: o = new Object(); //Now what? Instantiated? What's that?!
This allocates memory on the heap for the newly instantiated object.
profoundwhispers wrote: o = some_fuction_that_returns_a_newly_created_object(); //Now?
the actual newly created object will be on the heap. o itself is still a pointer/reference on the stack to that object.
profoundwhispers wrote: How about the first o that was allocated? ... What happens to the first instance?
The garbage collector will remove it from the system when it gets around to it, assuming nothing else is referencing it.
profoundwhispers wrote: What about if I want to destroy this o in memory because I simply don't need it anymore?!
If you don't need it anymore just don't reference it. The garbage collector will free the memory when it gets around to it.
One caveat is objects that have a Dispose() method. These usually have resources that the managed heap in .NET cannot garbage collect efficiently. When you no longer need these objects you should call Dispose(). The garbage collector would eventually Dispose it anyway, but it will take a few attempts at it.
Let me just say I'm a programming newbie. I have this problem that's been irritating me.
I have a list view in my app and I've specified a DataSource for it. I have other functions that are constantly updating the Array that is the DataSource (it's an array of integers, in this case.)
The only way I've found to have the ListView update is to set the DataSource to null and then reassign it. Is there a more elegant way to do this?
I've created an icon-file with a 16x16 icon and selected that file in the "Icon" property of my main form. This changes the icon in the top-left corner of the app, but it doesn't change the icon that appears in the ALT-TAB sequence pop-up. I suppose that I need a 32x32 icon for that purpose, but even if I create a such in the icon file - it still doesn't change from the default .Net icon when running the app. Any ideas ?
Do you know why it's important to make fast decisions? Because you give yourself more time to correct your mistakes, when you find out that you made the wrong one. Chris Meech on deciding whether to go to his daughters graduation or a Neil Young concert
Either change the App.ico file in your project, or replace it / add a new icon (presumably the same one as which you designated as your Form.Icon) and change the Application Icon to reference that icon in your project properties. You should at least have both a 16x16 and 32x32 icon for your .ico file.
I'm developing a set of Windows form controls that should extend the functionalities of the following classes:
public class MyPushButton : System.Windows.Forms.Button
public class MyCheckbox : System.Windows.Forms.CheckBox
public class MyRadioButton : System.Windows.Forms.RadioButton
I decided to derive a class from each of these base classes in order to get the right notifications from the base class events.
Now these custom controls should apply some graphic effect to the buttons through a set of properties that would be common to all of the "MyXXX" button classes: due to the fact that multiple inheritance is not supported in C#, how can I avoid to have all of the properties and their get/set helpers duplicated in each of the "MyXXX" classes?
After some serious research i've managed to display some balloon tooltips on a notifiyicon, hooked up to a windows form.
But i inteded to write a windows service instead of a form-based application.
Since you need a window handle to run the shell_notifyicon function, needed to display the balloon tooltips, and i don't seem to find the handle from a service, i have a problem
Does anybody know how to get the handle from a windows service, or any way to hook up a balloon tooltip to the notifyicon from a service??
Your service, if run as LocalSystem, will also have to have the "Allow service to interact with desktop" option checked in the Service snap-in. See your Control Panel\Administrative Tools for the snap-in.
public static IntPtr GetHInstance()
In an attempt to create a global hook using WH_KEYBOARD.
The problem I have is it doesn't work. It works globally with WH_KEYBOARD_LL but as soon as I use WH_KEYBOARD it doesn't work at all. This meaning it doesn't capture keyboard strokes in either the windows form or anywhere else. Now Dino's code worked fine for a local hook (aka the form) but I want a global or system hook.
Now I have the class he wrote in an external DLL but there must be something else i am missing. If anyone has any suggestions they would be very much appreciated.
Thanks very much.
Dino Esposito modified project and my test windows form can be found here
The WH_KEYBOARD_LL hook is called in your app. context so can easily be made in C#.
A global WH_KEYBOARD hook however executes in teh context of the app. that is recieving the keyboard message so your code has to be injected into every running process. This is NOT a good idea IMHO. It only seems to work if the m_filterfunc is exported from the DLL in the [EXPORTS] table.
If a hook is in place globally whether it is WH_MOUSE or WH_KEYBOARD or WH_KEYBOARD_LL the hook functions the exact same for each case. Nothing is injected into any running process, it doesn't work like that. A hook is ultimately a callback function that applications register with a particular system event. It is not injected into every running process as you say. Doing this with C# is no different then any other language as I am just using the windows API.
Now I have the code that can capture WH_MOUSE events at the thread or local application level but I need them to be captured at the global or system level. Any suggestions?
I take it you have read the MSDN article on hooks? It states:
....This is because global hook procedures are called in the process context of every application in the desktop, causing an implicit call to the LoadLibrary function for all of those processes....
If you only want to be aware of mouse or keyboard events system wide use a WH_JOURNALRECORD hook. Otherwise write your hook stuff in a standard DLL with an EXPORTS section.
To have the shell extract an image for your document, you must register an IconHandler and implement IExtractImage, as well as the necessary icon handler interfaces. For more information about the IExtractImage interface, which you can declare in .NET using COM interop, see http://msdn.microsoft.com/library/en-us/shellcc/platform/shell/reference/ifaces/iextractimage/iextractimage.asp[^]. For more information about creating icon handlers, see Creating Icon Handlers[^] in MSDN. This can all be done via a CCW (COM-Callable Wrapper) in .NET, but you'll have to re-declare all the interfaces, structs, and constants necessary. Fortunately, there isn't too many in this case.
As far as writing a browser plugin, that gets a lot more complicated and you might consider doing this in C++ because there's a lot of interfaces, structs, and constants that you'll need to use. It's not that you can't do it in .NET, just make sure you fully understand COM interoperability in .NET.
This uses MIME handlers to host controls like Acrobat, or your document has to be an Active Document like Word and other Office formats. For more information and documentation on MIME handlers (asynchronous pluggable protocols), see About Asynchronous Pluggable Protocols[^]. For more information about Active Documents, see http://msdn.microsoft.com/library/en-us/vccore/html/vcconactivedocuments.asp[^]. Internet Explorer, BTW, is an Active Document Container and can display Active Documents, as well as host any toolbars if they're exposed properly. Other containers like Word, Excel, PowerPoint, and even a few non-MS container applications could also container your document. This requires that your document class implements a few COM interfaces and that your document server is registered using regasm.exe or some other installation utility. Some custom registry editing (see the Microsoft.Win32.RegistryKey class) will be required.
I have created a windows application in CSharp that is using a web browser control.
When i did some coding to handle a chat window an exception was thrown with the following message:
"COM object that has been separated from its underlying RCW can not be used"
The chat browser window is constantly updating its content automatically.
My question is how can i work around this problem?
I appreciate any help you can give me.
Set EnableViewState to true and in the server event handler for the "Save" button (or whatever you call it), gather the values from each TextBox and save them to a database using ADO.NET. Search the CodeProject web site for examples. There's also several examples of inserting data into a database from ASP.NET using ADO.NET. For example, if you have a couple TextBoxes on the page and a button with the Client event handler save_Click, you could do something like the following:
privatevoid save_Click(object sender, EventArgs e)
if (!IsValid) return;
SqlConnection conn = new SqlConnection("...");
SqlCommand cmd = conn.CreateCommand();
cmd.CommentText = "INSERT INTO Table1 (FirstName, LastName) " +
"VALUES (@FirstName, @LastName)";
cmd.Parameters.Add("@FirstName", SqlDbType.NVarChar, 40).Value = textBox1.Text;
cmd.Parameters.Add("@LastName", SqlDbType.NVarChar, 40).Value = textBox2.Text;
catch (Exception e)
// Method to display error to user and perhaps log.