|
I'm writing an app for XP that will need to have a custom shutdown procedure. I'd like to initiate this procedure with the press of the physical power button on the computer. Is there any way to catch this event?
Thanks!
Dmitriy
|
|
|
|
|
|
The problem is that my shutdown procedure will take too much time and Windows will terminate it prematurely.
I need Windows to ignore the event (configure it to "Do Nothing" in the power management config), but for my application to handle it.
Thanks
|
|
|
|
|
I thought the shutdown event sends a shutdown message to all applications, and then waits for them to end ? Although, I guess if it will take too long, it will bring up a 'terminate this application', I'm pretty sure if you have an edited Word document for example, and you press shutdown and then hit 'cancel' on the 'do you want to save changes' dialog, it won't shut down. Therefore, you should have control to stop it, and then send your own shutdown event. If it's going to take that long, you should let the user know what's going on, or they'll think their PC is broken, and pull the plug out anyhow.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Hmm... I think you're right about the MS Word behavior. So you think there's an event that an application can generate that makes Windows cancel the shutdown? Any idea where I can read up on this?
|
|
|
|
|
According to the MSDN link I gave you above, the SessionEndEventArgs object passed in has a 'cancel' property. If you set it to true, you cancel the request for shutdown.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Sorry, somehow I spaced out and didn't see the link. That's exactly what I wanted to know, thanks!!!
-Dmitriy
|
|
|
|
|
I have used Spy++ to obtain the handle of a Window Panel and TreeView. I now want to use this handle to grab the tree. I don't understand how to do this ?? Any suggestions.
Once I grab the tree I want to be able to store this tree in a file.
Could someone please give me some direction here
Abhishek Karnik
|
|
|
|
|
You can't create a .NET TreeView instance from a handle to a window.
One way would be to send windows messages to this window handle to get information about the tree. Search MSDN for treeview messages, they usually start with TVM_...
But nevertheless, I think your question doesn't belong to the C# forum. Try the Visual C++ forum instead.
Regards,
mav
|
|
|
|
|
Hey,
Thanx ..lemme give it a shot there.
Regards,
Abhishek
|
|
|
|
|
Hy, I Got a programming question on .NET remoting in C#:
Following scenario:
I've a server application and client applications with the graphical front end.
the server app marshales an object(a class for all the settings the client apps
need to know) via:
----------------------------------- server code snippet----------------------------------
BinaryServerFormatterSinkProvider serverProv = new BinaryServerFormatterSinkProvider();
serverProv.TypeFilterLevel = TypeFilterLevel.Full;
BinaryClientFormatterSinkProvider clientProv = new BinaryClientFormatterSinkProvider();
IDictionary props = new Hashtable();
props["port"] = 9999;
m_TcpChan = new TcpChannel(props, clientProv, serverProv);
ChannelServices.RegisterChannel(m_TcpChan);
sO = new ServerObject(mainClass.loadSets(), (IServer)this, mainClass.loadLogs());
sO.Clients = new ArrayList();
obj = RemotingServices.Marshal(sO, "settings");
----------------------------------------------------------------------------------------
and the client apps are "connecting" via:
------------------------------------client code snippet---------------------------------
TCP = new TcpChannel(0);
ChannelServices.RegisterChannel(TCP);
sO = (Interface.ServerObject) Activator.GetObject(typeof (Interface.ServerObject), "tcp://" + remoteIP + ":9999/settings");
----------------------------------------------------------------------------------------
know I can access sO.settings... to retrieve data I need on the client's side.
but there're also "remote methods" I cann call via:
sO.IServer.myServerRemoteMethod();
and: sO.ICLient.myClientremoteMethod(); (on the server side)
up to this point everything is working correctly!
my problem is that after somte time I can't call the remote methods anymore, the error is: "
System.Runtime.Remoting.RemotingException: Requested Service not found....
so I looked around some time to solve my problem and I read something about "Object Lifetime" and
"Leased Based Manager", I think my "remote methods" are destroyed after that standart 5min. of lifetime,
is that correct?! do I just have to return "null" in the overriden InitializeLifetimeService()
method? how to? that way?
public override Object InitializeLifetimeService()
{
ILease lease = (ILease)base.InitializeLifetimeService();
if (lease.CurrentState == LeaseState.Initial)
{
lease.InitialLeaseTime = TimeSpan.FromMinutes(1);
lease.SponsorshipTimeout = TimeSpan.FromMinutes(2);
lease.RenewOnCallTime = TimeSpan.FromSeconds(2);
}
return null;
}
I'm totally confused...
btw: I don't even know, if I have client activated or server sided object,
or whether I'm using singleTon or singleCall...
What would be the best solution for this Programm?
I'm looking foward for any help!
OpaKnack
|
|
|
|
|
Hi!
You're using an object that's marshalled explicitely, so it's similar to a singleton, but not exactly the same (a singleton doesn't exist before the first client requests one, for example).
For your ServerObject not to die you do have to override InitializeLifetimeService() , but you can skip all that ILease stuff and just return null.
Another important point is to watch the scope of your ServerObject sO .
If you declare it within your startup routine, it'll fall out of scope when startup is finished and will get garbage collected.
So it should be a member of a class you keep alive as long as your server application is running.
Regards,
mav
|
|
|
|
|
Thank you for you're quick response!
I think I've to override InitializeLifetimeService() on my server App, don't I?
I already declared "ServerObject sO" in my Class, so I can use it outside the startup routine.
But if my serverObject dies after 5min.(so that I can't use the remote methods anymore) why can I still access the "settings" instance in the ServerObject(sO.settings)?
That means:
I can use: sO.settings.userName (it's a string)
but I can't use: sO.IServer.myRemoteMethod()
OpaKnack
|
|
|
|
|
You'll have to override InitializeLifetimeService in your ServerObject class, which has to be derived from MarshalByRefObject , to be precise.
I might be wrong, but I guess the proxy that's created for comm' with the server object could hold your server object's properties in some sort of cache, so that it doesn't have to marshal all get-property calls to the original object. So the proxy could be still alive and provide property values, although the remote object has died already. With method calls the proxy doesn't have a chance but to marshal the call. And when the remote object has died there's nobody to execute the method.
Hope this helps,
mav
|
|
|
|
|
Is there an event that gets generated when a node is added/inserted somewhere in the tree?
Gary Kirkham
Forever Forgiven and Alive in the Spirit
He is no fool who gives what he cannot keep to gain what he cannot lose. - Jim Elliot
Me blog, You read
|
|
|
|
|
Surprisingly,[^] it doesn't look that way.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Thanks...I had looked through the same documentation...I was hoping that there was some "trick" that would let me do it (like trapping a message in WndProc, for example).
There are things I dislike about .Net. This would be so easy if .Net would allow me to set the Nodes property. Then I could supply a reference to a collection derived from the TreeNodeCollection class. I could then implement whatever events I wanted. I guess that allowing me to do that might create other problems if not implemented properly.
Gary Kirkham
Forever Forgiven and Alive in the Spirit
He is no fool who gives what he cannot keep to gain what he cannot lose. - Jim Elliot
Me blog, You read
|
|
|
|
|
Gary Kirkham wrote:
(like trapping a message in WndProc, for example).
Hmmm.... that could work. I mean, it has to be creating a windows tree at the end of the day, right ? And I'm sure THEY had an event for adding/removing. I guess the thing is, you add and remove through code, right ? So perhaps they expect you to know when you do. Maybe if you override the tree class and override methods to add and remove items, and specify your own event ?
Or can a tree view have items added to it through other means ?
Gary Kirkham wrote:
There are things I dislike about .Net.
Number one for me is that, unlike MFC, there's no source code provided.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Christian Graus wrote:
Number one for me is that, unlike MFC, there's no source code provided.
Actually there is!! .NET Reflector[^]
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
|
|
|
|
|
Wow - that's really neat !!!
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Christian Graus wrote:
Wow - that's really neat !
So, you didn't really know about it?
That tool has saved my life so many times! Whenever you have a little problem with the framework (and third-party assemblies), use it to check what's going on under the hood... and in VB.NET C# code.
Enjoy!!
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
|
|
|
|
|
Luis Alonso Ramos wrote:
So, you didn't really know about it?
I obviously knew it was possible, and even considered that it probably existed, but I've never seen it before. Knowing in theory is not as cool as seeing it pop up on the screen
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Wow 2 questions in 1 day...
How do you fire off a "clean up" function if a user simply closes the browser?
I have a customized cache that I would like to flush before they are gone. (This is not the built in cache object of .NET)
The INPROC is set in my web.config and I have code in the Session_End portion of my Global.asax file. However, I have determined through debugging that I am hitting the Session_Start, but not the Session_End.
Thank you.
William
|
|
|
|
|
There is no event on the server that says the user closed the browser. The only thing you can do is wait for the user's session to timeout, which, by default, I think, is 20 minutes. Then your Session_End code gets kicked off, if it's still running under the debugger.
You might even catch the Session_End event being kicked off when you start your app under the debugger again. It might kick off first thing before the new Session_Start event is fired.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Thanks Rage.
The knowledge is helpful.
BTW, 2Bad Rage is gone.
Will-Keep-Listening-Anyway
|
|
|
|