What's new
  • Visit Rebornbuddy
  • Visit Resources
  • Visit API Documentation
  • Visit Downloads
  • Visit Portal
  • Visit Panda Profiles
  • Visit LLamamMagic

Exception Caught

DerpProgrammer

Community Developer
Joined
Mar 16, 2015
Messages
33
Reaction score
0
How do I make my plugin not throw an exception when ArcheAge gets closed or disconnected? I just want the plugin to stop gracefully. I've put most everything inside a try/catch... But I get the error: Object 'RandomCharacters' has been disconnected or does not exist at the server.
Any help?
 
How do I make my plugin not throw an exception when ArcheAge gets closed or disconnected? I just want the plugin to stop gracefully. I've put most everything inside a try/catch... But I get the error: Object 'RandomCharacters' has been disconnected or does not exist at the server.
Any help?
1. Use the property gameState to control the state of the client.
2. Before each use of some object, check its not null.
3. Use object identifiers (unique ID) in order not to use object references.
4. Use the wrapper objects for-performance storage in the program.
5. In cycles to handle exceptions:
Code:
while (true)
{
	try
	{
		//cancelToken.ThrowIfCancellationRequested() if you use Task
		//Logic
		Thread.Sleep(100);
	}
	catch (AppDomainUnloadedException) {/*skip*/  Log("AppDomainUnloadedException "); } //some time
	catch (ThreadAbortException) { /*skip*/ Log("ThreadAbortException "); } //every time
	catch (OperationCanceledException) { break; } //if you use Task
	catch (Exception error) //other errors
	{
		host.Log(error.ToString(), System.Drawing.Color.Red);
	}
}
Combine methods, and everything should work.
 
Thanks! I will definitely use this!

I would also add:
If you are using a thread, use Thread.Join(). This allows you to correctly complete thread!
Example:
Code:
private Thread  mainThread;
private bool needToStop = false;

public void PluginRun()
{
	needToStop = false;

	mainThread = new Thread(Run);
	mainThread.IsBackground = true;
	mainThread.SetApartmentState(ApartmentState.STA);
	mainThread.Start();

	try
	{
		while (!needToStop)
			Thread.Sleep(10);
	}
	catch(ThreadAbortException)
	{
	   //skip
	}
	finally
	{
		[B]mainThread.Join(); [/B]
	}
}
 
I'll admit, I'm having trouble wrapping my head around thread.Join(); and SetApartmentState()... I'll read up on threading. Currently i'm using multiple threads, and aborting them in my PluginStop(). I haven't done too much where the threads need to interact with one another. Thanks for the assistance!
 
Back
Top