using System;
namespace Frankfort.Threading
{
public interface IThreadWorkerObject
{
/// <summary>
/// This method is called by the Scheduler as the main entryPoint to start working.
/// 作为开启程序的主要进入点,这个方法将被调度器调用
/// - Note: Make sure it doesn't throw any errors, because errors outside of the Mainthread are "eaten" by Unity.
/// 要确保此方法不抛出错误,因为主线程外的错误将被Unity忽视
/// - You can enable "savemode" if required, which executes all the work within a Try-catch statement to keep it going...
/// 需要的话可以写try-catch
/// Example:
///
/// private bool isAborted;
/// public void ExecuteThreadedWork()
/// {
/// long i = 10000000;
/// while (--i > -1 && !isAborted)
/// result++;
/// }
///
/// public void AbortThreadedWork()
/// {
/// isAborted = true;
/// }
/// </summary>
void ExecuteThreadedWork();
/// <summary>
/// When called by the Scheduler, do whatever you need to do to directly interupt/stop the work in progress.
/// Why no aborting the thread? Its not possible to interupt an loop without calling Thread.Abort() or Thread.Join().
///
/// This freamwork does NOT use Thread.Abort & Thread.Join because of webplayer-sandbox restrictions etc.
/// 这个框架不使用Thread.Abort 和 Thread.Join 因为网络播放器沙箱的限制
/// Therefore its up to you to implement a way to always directly abort the process as shown in the example bellow.
/// 因此要自己创建一个方法
/// - Note: Make sure it doesn't throw any errors, because errors outside of the Mainthread are "eaten" by Unity.
/// 不能抛出错误
/// - You can enable "savemode" if required, which executes all the work within a Try-catch statement to keep it going...
/// 可以使用try-catch
///
/// Example:
///
/// private bool isAborted;
/// public void ExecuteThreadedWork()
/// {
/// long i = 10000000;
/// while (--i > -1 && !isAborted)
/// result++;
/// }
///
/// public void AbortThreadedWork()
/// {
/// isAborted = true;
/// }
/// </summary>
void AbortThreadedWork();
}
}
unity多线程的学习:Loom-IThreadWorkerObject部分
最新推荐文章于 2023-05-31 10:49:29 发布