How to detect a Kill Process event
Tag : chash , By : robinator
Date : March 29 2020, 07:55 AM
seems to work fine if it's a winform, you can capture the event FormClosing and check the CloseReason: None
WindowsShutDown
MdiFormClosing
UserClosing
TaskManagerClosing
FormOwnerClosing
ApplicationExitCall
|
How to detect a kill process event, a computer's shut down and computer's crash
Date : March 29 2020, 07:55 AM
should help you out You may handle WM_QUIT as suggested above. There is also WM_QUERYENDSESSION and its family. For service that without GUI, use RegisterServiceCtrlHandlerEx to get notified.
|
Binding an event to a non object sender Event Handling
Tag : chash , By : Big Ant
Date : March 29 2020, 07:55 AM
Hope this helps Your EventHandler's first parameter should be of type object then use one of the following ways: protected void AddEvent(object sender, EventArgs e)
{
//Cast to LinkButton
var linkButton = (LinkButton)sender;
//Or use is keyword like below
if (sender is LinkButton)
{
}
//Or use as keyword
LinkButton linkButton = sender as LinkButton;
if (linkButton != null)
{
}
}
|
Casting the sender of an event to find the value in a Dictionary that fired the event
Tag : chash , By : user178709
Date : March 29 2020, 07:55 AM
should help you out It does indeed work as it is. One improvement could be wrapping the PropertyChanged event information in a new custom event and a new EventArgs of your own and have the Name and the opcVariable instance part of that event. This way you avoid any casting that can lead to runtime error. Here is an example of the EventArgs: public class YourEventArgs : EventArgs
{
public string Name {get;set;}
public int OpcVariableVtqValue {get;set;}
// If you still need it.
public string PropertyName {get;set;}
}
public interface IAlsVariable
{
event EventHandler<YourEventArgs> YourEvent;
}
public class SomeAlsVariableImpl : IAlsVariable
{
public string Name {get;}
public event EventHandler<YourEventArgs> YourEvent;
// Call this method any time you need to raise the event.
private void RaiseYourEvent(int opcVariableVtqValue)
{
YourEvent?.Invoke(this, new YourEventArgs
{
Name = Name,
OpcVariableVtqValue = opcVariableVtqValue,
}
}
}
foreach (var clusterManager in clusterManagers)
{
var clusterName = clusterManager.Name;
string opcDataSourceServer = "server/" + clusterName + ":[2:http://www.alstom.com/Transport/Iconis/S2K/Data]<Organizes>2:S2KServer<Organizes>2:S2KTerritoryMngt<Organizes>2:TASSObject<HasComponent>2:OperatorAudibleSev";
var opcVariable = m_alsApplication.Database.GetVariable(opcDataSourceServer, null);
opcVariable.YourEvent += OpcVariable_YourEvent;
m_operatorAudibleSevServerVariables.Add(clusterManager.Name, opcVariable);
}
private void OpcVariable_YourEvent(object sender, YourEventArgs e)
{
UpdateAlarmSound(e.Name, e.OpcVariableVtqValue));
}
|
How to implement event sender - event receiver game objects in unity?
Date : March 29 2020, 07:55 AM
I wish this helpful for you I have class "A", which will send event "a". Classes that are subscribing to event "a" will react to this event. Other classes can subscribe to event "a" without changing anything in class "A"; , There are probably many ways to do this. Public static List public class A : MonoBehaviour
{
public static List<A> AvailableAs = new List<A>();
private void Awake()
{
if(!AvailableAs.Contains(this)) AvailableAs.Add(this);
}
private void OnDestroy()
{
if(AvailableAs.Contains(this)) AvailableAs.Remove(this);
}
public void SomePublicMethod()
{
// magic
}
}
public class B : MonoBehaviour
{
// run the method on all currently registered A instances
public void DoIt()
{
foreach(var a in A.AvailableAs)
{
a.SomePublicMethod();
}
}
}
namespace ANamespace
{
public static class AEventHandler
{
internal static event Action OnInvokeA;
public static void InvokeAEvent()
{
if(OnInvokeA != null) OnInvokeA.Invoke();
}
}
}
namespace ANamespace
{
public class A : MonoBehaviour {
private void Awake()
{
// it is save to remove a callback first even
// if it was not added yet. This makes sure it is
// added only once always
AEventHandler.OnIvokeA -= SomePrivateMethod;
AEventHandler.OnIvokeA += SomePrivateMethod;
}
private void OnDestroy()
{
AEventHandler.OnIvokeA -= SomePrivateMethod;
}
private void SomePrivateMethod()
{
// magic
}
}
}
// invoke the event and whoever is added as listener will do
// whatever he registered
// in this case all A instances execute their method
AEventHandler.InvokeAEvent();
public class A : MonoBehaviour
{
public UnityEvent OnSomethingHappened = new UnityEvent();
private void SomeMethodIWillRun()
{
//...
OnSomethingHappened.Invoke();
}
}
public class B : MonoBehaviour
{
public A referenceToA;
private void Start()
{
referenceToA.OnSomethingHappened.AddCallback(OnASomethingHappened);
}
private void OnDestroy()
{
referenceToA.OnSomethingHappened.RemoveCallback(OnASomethingHappened)
}
private void OnASomethingHappened()
{
//
}
}
|