|
Christian Graus wrote: using is always good practice.
Thanks,
Assume I am not calling the dispose method and not using the using keyword. Then how long unmanaged object would be in memory ? Or will it automatically disposed when scope ends ?
|
|
|
|
|
N a v a n e e t h wrote: Then how long unmanaged object would be in memory ?
If you create an object which contains an unmanaged object, it will remain active until garbage collection picks the object up. You should not risk this, regardless of the fact that anythign in a using block probably lives for such a short time that it should, in theory, be collected pretty quickly.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Christian Graus wrote: f you create an object which contains an unmanaged object, it will remain active until garbage collection picks the object up
The garbage collector will not pick up an unmanaged object. That's why it is called unmanaged.
Or am I missing something?? Must be the case then Christian is always right, isn't he?
-^-^-^-^-^-
no risk no funk ................... please vote ------>
|
|
|
|
|
I am assuming that the 'unmanaged object' is something that is being held in a managed object, for example, a HDC in a graphics object. In this instance, when the graphics object is finalised, it should release the HDC. I was wording my reply carefully, I wasn't sure if he realised that an IDisposable is, by definition, a managed object. Of course, if you create an HDC directly via p/invoke, no GC will ever occur, nor is the object going to impliment IDisposable, making the whole discussion moot.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
They both to the same (well using first checks if c1 isn't null) but the first one is easier to understand and use
|
|
|
|
|
OK, I thought that at first, but I wasn't sure if using generates the try block. I guess it's the logical thing for it to do.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
These are essentially the same thing. The using statement is "syntactic sugar" that provides an easier way to write a try/finally block. That being said, the using is the recommended "best practice" because it guarantees that the pattern is followed properly (even if that pattern changes at some point in a future release of .NET) and is easier to read.
N a v a n e e t h wrote: what will happen to the object if any error happened in between the process ? Will it be disposed ?
Since they are equivalent, the behavior would be the same as you get with the try/finally block.
|
|
|
|
|
Hello, iv recently started to use C#, and now iv found i want to wait for an event. Im writing an application that reacts to diffrent Windows Live Messenger events. For instance, plays a sound when a message is receieved.
Im using the IMessengerAPI by adding a com reference to it in my project. I don't really need to do anything in my applications unless there is an event to react to. So i just want it to Sleep(); while there are no events, and then when an event arrives, handle it, and then go back to sleep.
So i need to create a function, WaitForAnyOfTheMsnAPIEvents(); or something like that. That Sleeps the application while it listens for events. How do i do this?
<br />
static class Program<br />
{<br />
static MessengerAPI.Messenger MSN = new MessengerAPI.Messenger();<br />
<br />
[STAThread]<br />
static void Main()<br />
{<br />
MSN.OnIMWindowDestroyed += new MessengerAPI.DMessengerEvents_OnIMWindowDestroyedEventHandler(MSN_OnIMWindowDestroyed);<br />
<br />
while(true)<br />
{<br />
WaitForAnyOfTheMsnAPIEvents(); }<br />
}<br />
<br />
static void MSN_OnIMWindowDestroyed(object pIMWindow);<br />
}<br />
Sorry if im stupid, im very new to C#, but i think this should be possible, in C++ you could do something similiar for events, WaitForMultipleObjects() etc..
Thanks in advance.
|
|
|
|
|
Just write a windows program which does nothing, this will create a message pump that will then respond to any messages that occur. It's automatic, just like it was in C++. WaitForMultipleObjects was something different, you can do that in C#, also.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Ahh i see! Thanks, but how do i create a windows program without a window, that still has a messagepump? Could you point me in the right direction? My application dosn't need a window, it uses messagebox popups.
|
|
|
|
|
One simple way would be to create a window that is not visible and does not appear in the taskbar. I'd expect you'd want your app either in the taskbar or the system tray, tho, so users can interact with it, even if only to exit it.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Hi!
You can achieve this very easily by replacing your while(true) loop with a call to Application.Run() .
To shut down the application just call Application.Exit() (in the OnIMWindowDestroyed event handler, for example).
Regards,
mav
--
Black holes are the places where God divided by 0...
|
|
|
|
|
Hai every body,
I have to display a message box from a windows service.
Best Regards,
M. J. Jaya Chitra
|
|
|
|
|
A windows service has no user interface because it can start running before a user has logged into the system and will continue to run when they log off.
|
|
|
|
|
Can you give me a solution to do this.
Can i create a form in the service and show that form with that message by calling it.
Best Regards,
M. J. Jaya Chitra
|
|
|
|
|
If you can get a handle to the desktop window, then you can make that the parent of your message box. I think you need p/invoke for this, but you may not.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
You have 2 options:
1. enable "Interact with desktop" ... this is not such a good solution, direct interaction with the desktop can be a security risk.
2. use remoting to interact with a front end app running in the task tray. THis is a right bastard to get working :p but is the "correct" way
|
|
|
|
|
how to give white spaces
my string is link this...
<compile include="AssemblyInfo.cs"><subtype>Code
and i want to show like that
<compile include="AssemblyInfo.cs">
<subtype>Code
|
|
|
|
|
Situ14 wrote: how to give white spaces
my string is link this...
Code
and i want to show like that
Code
I would say there is more than enough white space already.
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Environment.NewLine gives a carriage return. But, we have no idea how you render this, or where, so we can't really help much more than that
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
I believe that you should have something like this:
String s="how to give white spaces"+Convert.ToChar(10)+Convert.ToChar(13)+"my string is link this..."+Convert.ToChar(10)+Convert.ToChar(13)+"Code"+Convert.ToChar(10)+Convert.ToChar(13)+Convert.ToChar(10)+Convert.ToChar(13)+"and i want to show like that";
Regards,
Thomas Stockwell
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Visit my homepage Oracle Studios[ ^]
|
|
|
|
|
I created an OL 2003 VSTO Addin in C#. I used the NewInspector event to add a toolbar whenever a Mail is opened.
It works fine when i open a Mail in Outlook (e.g. New) or when i create the mail via the contextmenu in Windows Explorer.
But the event doesn´t fire, when i create a new Mail via Excel (File - send to - E Mail attachement).
How can i solve the problem?
Any Help will be appreciated
EisMayer
|
|
|
|
|
How do i calculate subtitems[4] * subtitems[5] + next item to a label..
like this:
(subtitems[0]),subtitems[1],subtitems[2],subtitems[3], 3.5, 100
(subtitems[0]),subtitems[1],subtitems[2],subtitems[3], 3.5, 100
awnser should be = 700..
tnx
|
|
|
|
|
You have to convert the subitems to numbers before you can carry out a calcualtion.
|
|
|
|
|
How, can you give me a example??
i´m pretty new on c#
can you give me a little code
tnx
Best regards
//André
|
|
|
|