本文整理汇总了C#中LockType类的典型用法代码示例。如果您正苦于以下问题:C# LockType类的具体用法?C# LockType怎么用?C# LockType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
LockType类属于命名空间,在下文中一共展示了LockType类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: Lock
public Lock(System.Threading.ReaderWriterLock rwl, LockType lt)
{
rwlock = rwl;
if (type == LockType.ForReading)
rwl.AcquireReaderLock(-1);
else if (type == LockType.ForWriting)
rwl.AcquireWriterLock(-1);
}
开发者ID:H1GHGuY,项目名称:ServerCheckerV4,代码行数:8,代码来源:Lock.cs
示例2: Calculator
public Calculator(LockType lockType, int lower, int upper, int modulus, int threads, ProgramMode programMode, string hash)
{
this.lower = lower; this.upper = upper;
this.modulus = modulus; this.threads = threads;
this.hash = hash;
LockObject locker = CreateLocker(lockType);
loop = CreateLoop(locker, programMode);
}
开发者ID:Dutchman97,项目名称:ConcurrencyPracticum1,代码行数:9,代码来源:Calculator.cs
示例3: GetLock
public bool GetLock(Guid entityId, LockType lockType)
{
LockType value;
if (locks.TryGetValue(entityId, out value) && lockType == value)
return true;
var sessionManager = SessionManager.Manager;
var session = sessionManager.GetSession(sessionManager.Current);
using (var transaction = session.DbInfo.Connection.BeginTransaction(IsolationLevel.Serializable))
{
try
{
var reader = ExecuteReader(entityId, session, (SqlTransaction)transaction);
var query = CREATE_QUERY;
if (reader.HasRows)
{
while (reader.Read())
{
var sessionId = reader.GetGuid(0);
var type = reader.GetInt16(1);
if (!Enum.TryParse<LockType>(type.ToString(), out value))
{
reader.Close();
throw new Exception("Wrong LockType fetched. " + type);
}
if ((lockType == LockType.Write || value == LockType.Write) && session.Id.CompareTo(sessionId) != 0)
{
reader.Close();
throw new Exception(string.Format("Can't get {0} lock for {1}, session {2} has {3} lock.", lockType.ToString(), SessionManager.Manager.GetSession(session.Id).Name, SessionManager.Manager.GetSession(sessionId).Name, value.ToString()));
}
if (session.Id.CompareTo(sessionId) == 0)
query = UPDATE_QUERY;
}
}
reader.Close();
ExecuteNonQuery(query, entityId, session, lockType, transaction);
transaction.Commit();
Console.WriteLine(string.Format("Session {0} adquired {1} lock for VersionId: {2}", session.Name, lockType.ToString(), entityId));
if (locks.ContainsKey(entityId))
locks[entityId] = lockType;
else
locks.Add(entityId, lockType);
}
catch (Exception ex)
{
transaction.Rollback();
Console.WriteLine(ex.Message);
return false;
}
}
return true;
}
开发者ID:Kaike23,项目名称:CoarsePessimisticLock,代码行数:56,代码来源:LockManager.cs
示例4: GetLock
public void GetLock(Guid entityId, LockType lockType)
{
LockType value;
if (locks.TryGetValue(entityId, out value) && lockType == value)
return;
var connection = new SqlConnection(SQL_CONNECTION);
connection.Open();
using (var transaction = connection.BeginTransaction(IsolationLevel.Serializable))
{
try
{
var reader = ExecuteReader(entityId, connection, transaction);
var query = CREATE_QUERY;
if (reader.HasRows)
{
while (reader.Read())
{
var currentOwnerId = reader.GetGuid(0);
var type = reader.GetInt16(1);
if (!Enum.TryParse<LockType>(type.ToString(), out value))
{
reader.Close();
throw new Exception("Wrong LockType fetched. " + type);
}
if ((lockType == LockType.Write || value == LockType.Write) && Session.Id.CompareTo(currentOwnerId) != 0)
{
reader.Close();
throw new Exception(string.Format("Can't get {0} lock for {1}, session ID '{2}' has {3} lock.", lockType.ToString(), Session.Name, currentOwnerId.ToString(), value.ToString()));
}
if (Session.Id.CompareTo(currentOwnerId) == 0)
query = UPDATE_QUERY;
}
}
reader.Close();
ExecuteNonQuery(query, entityId, lockType, connection, transaction);
transaction.Commit();
if (locks.ContainsKey(entityId))
locks[entityId] = lockType;
else
locks.Add(entityId, lockType);
}
catch (Exception ex)
{
transaction.Rollback();
throw ex;
}
finally
{
connection.Close();
}
}
}
开发者ID:Kaike23,项目名称:ImplicitLock,代码行数:56,代码来源:LockManager.cs
示例5: UpgradeToWriterLock
public void UpgradeToWriterLock()
{
System.Diagnostics.Debug.Assert(type == LockType.ForReading);
if (type == LockType.ForReading)
{
rwlock.UpgradeToWriterLock(-1);
type = LockType.ForWriting;
}
}
开发者ID:H1GHGuY,项目名称:ServerCheckerV4,代码行数:10,代码来源:Lock.cs
示例6: DowngradeToReaderLock
public void DowngradeToReaderLock()
{
System.Diagnostics.Debug.Assert(type == LockType.ForWriting);
if (type == LockType.ForWriting)
{
System.Threading.LockCookie c = cookie.Value;
rwlock.DowngradeFromWriterLock(ref c);
cookie = null;
type = LockType.ForReading;
}
}
开发者ID:H1GHGuY,项目名称:ServerCheckerV4,代码行数:11,代码来源:Lock.cs
示例7: CreateLocker
LockObject CreateLocker(LockType lockType)
{
switch (lockType)
{
case LockType.TaS:
return new TTaSLock();
case LockType.Lock:
return new StatementLock();
default:
throw new NotImplementedException();
}
}
开发者ID:Dutchman97,项目名称:ConcurrencyPracticum1,代码行数:12,代码来源:Calculator.cs
示例8: Prepare
public static ILockHelper Prepare(this ReaderWriterLockSlim lok, LockType type)
{
switch (type)
{
case LockType.Read:
return new ReadLockHelper(lok);
case LockType.UpgradeableRead:
return new UpgradeableReadLockHelper(lok);
case LockType.Write:
default:
return new WriteLockHelper(lok);
}
}
开发者ID:wli3,项目名称:Its.Log,代码行数:13,代码来源:Lock.cs
示例9: Create
public static ILock Create(LockType lockType)
{
switch (lockType)
{
case LockType.NoLock:
return new NoLock();
case LockType.SpinLock:
return new SpinLock();
case LockType.ClrLock:
return new ClrLock();
default:
return null;
}
}
开发者ID:nipacnavi,项目名称:Computers,代码行数:17,代码来源:LockFactory.cs
示例10: ProcessAsync
public void ProcessAsync(Func<Task> func, LockType lockType)
{
if (_isStopped)
throw new TaskCanceledException("Fiber was stopped");
switch (lockType)
{
case LockType.None:
func();
break;
case LockType.Read:
_readLockedQueue.Post(func);
break;
case LockType.Write:
_writeLockedQueue.Post(func);
break;
}
}
开发者ID:Rurouni,项目名称:MassiveOnlineUniversalServerEngine,代码行数:18,代码来源:ReadWriteLockingFiber.cs
示例11: AdcquireLock
public void AdcquireLock(Guid lockable, Guid owner, LockType type)
{
var lockInfo = GetLockInfo(lockable, owner);
if(!lockInfo.HasLock(type))
{
if(CanClaimLock(lockable, owner, type))
{
var db = ApplicationManager.INSTANCE.GetDbProvider();
var connection = db.CreateConnection();
connection.Open();
try
{
var transaction = connection.BeginTransaction(IsolationLevel.Serializable);
try
{
using (var command = connection.CreateCommand())
{
command.CommandType = CommandType.Text;
command.Transaction = transaction;
if (lockInfo.LockType == LockType.None)
command.CommandText = string.Format(INSERT_SQL, lockable, owner, (byte)type);
else
command.CommandText = string.Format(UPDATE_SQL, (byte)type, lockable, owner);
command.ExecuteNonQuery();
transaction.Commit();
}
}
catch(DbException e)
{
transaction.Rollback();
throw new ConcurrencyException("Unable to lock: " + lockable);
}
}
finally
{
connection.Close();
}
}
else
{
throw new ConcurrencyException("Unable to lock: " + lockable);
}
}
}
开发者ID:afrancocode,项目名称:PessimisticOfflineReadWriteLock,代码行数:44,代码来源:ReadWriteLockManager.cs
示例12: LockState
internal LockState(LockManager LockManager, LockType LockType, IEnumerable<LockableBase> BaseDataObjectStateTrackers, Action<LockState> StateChanged, Action<LockState> ReportStale, TimeSpan Timeout)
{
if (LockManager == null)
throw new ArgumentNullException ("LockManager");
if (BaseDataObjectStateTrackers == null)
throw new ArgumentNullException ("BaseDataObjects");
if (StateChanged == null)
throw new ArgumentNullException ("StateChanged");
if (ReportStale == null)
throw new ArgumentNullException ("ReportStale");
lockManager = LockManager;
lock_status = new object ();
reportStale = ReportStale;
lockType = LockType;
lockables = new SortedSet<LockableBase> (BaseDataObjectStateTrackers);
stateChanged = StateChanged;
defaultTimeout = Timeout;
if (Timeout == TimeSpan.Zero) {
Timeout = TimeSpan.MaxValue;
}
}
开发者ID:vebin,项目名称:BD2,代码行数:21,代码来源:LockState.cs
示例13: AddRecordLock
//public static LockType AddRecordLock(string DBAlias, string TableName, string KeyFields, string KeyValues, ref string UserID)
//{
// return AddRecordLock(DBAlias, TableName, KeyFields, KeyValues, ref UserID, LockType.Updating);
//}
public static LockType AddRecordLock(string DBAlias,string TableName, string KeyFields, string KeyValues, ref string UserID, LockType lt)
{
if (ServerConfig.RecordLockInDatabase)
{
return RecordLockInDB.AddRecordLock(DBAlias, TableName, KeyFields, KeyValues, ref UserID, lt);
}
else
{
//while (lockinuse)
//{
// Thread.Sleep(100);
//}
LockType retval;
//lockinuse = true;
XmlDocument xml = new XmlDocument();
xml.Load(RecordFileName);
XmlNode nodeDBAlias = FindAlias(xml, DBAlias);
if (nodeDBAlias == null)
{
CreatRecord(xml, DBAlias, TableName, KeyFields, KeyValues, UserID, lt);
return LockType.Idle;
}
else
{
XmlNode nodeTable = FindTable(nodeDBAlias, TableName);
if (nodeTable == null)
{
CreatRecord(xml, nodeDBAlias, TableName, KeyFields, KeyValues, UserID, lt);
retval = LockType.Idle;
}
else
{
XmlNode nodeRecord = FindRecord(nodeTable, KeyFields, KeyValues);
if (nodeRecord == null)
{
CreatRecord(xml, nodeTable, KeyFields, KeyValues, UserID, lt);
retval = LockType.Idle;
}
else
{
if (nodeRecord.Attributes["UserID"].Value == UserID)
{
switch (lt)
{
case LockType.Updating: nodeRecord.Attributes["Status"].Value = "Updating"; break;
case LockType.Deleting: nodeRecord.Attributes["Status"].Value = "Deleting"; break;
default: nodeRecord.Attributes["Status"].Value = ""; break;
}
retval = LockType.Idle;
xml.Save(RecordFileName);
}
else
{
UserID = nodeRecord.Attributes["UserID"].Value;
switch (nodeRecord.Attributes["Status"].Value)
{
case "Updating": retval = LockType.Updating; break;
case "Deleting": retval = LockType.Deleting; break;
default: retval = LockType.Other; break;
}
}
}
}
}
//lockinuse = false;
return retval;
}
}
开发者ID:san90279,项目名称:UK_OAS,代码行数:73,代码来源:RecordLock.cs
示例14: LockHandle
internal LockHandle(ReaderWriterLockSlim rwlock, LockType type)
{
this.rwlock = rwlock;
this.type = type;
}
开发者ID:rikkus,项目名称:cadenza,代码行数:5,代码来源:ReaderWriterLockSlimCoda.cs
示例15: Run
public override float Run()
{
Player player = KickStarter.player;
if (KickStarter.playerInput)
{
if (IsSingleLockMovement ())
{
doLeftLock = doUpLock;
doRightLock = doUpLock;
doDownLock = doUpLock;
}
if (doUpLock == LockType.Disabled)
{
KickStarter.playerInput.SetUpLock (true);
}
else if (doUpLock == LockType.Enabled)
{
KickStarter.playerInput.SetUpLock (false);
}
if (doDownLock == LockType.Disabled)
{
KickStarter.playerInput.SetDownLock (true);
}
else if (doDownLock == LockType.Enabled)
{
KickStarter.playerInput.SetDownLock (false);
}
if (doLeftLock == LockType.Disabled)
{
KickStarter.playerInput.SetLeftLock (true);
}
else if (doLeftLock == LockType.Enabled)
{
KickStarter.playerInput.SetLeftLock (false);
}
if (doRightLock == LockType.Disabled)
{
KickStarter.playerInput.SetRightLock (true);
}
else if (doRightLock == LockType.Enabled)
{
KickStarter.playerInput.SetRightLock (false);
}
if (IsInFirstPerson ())
{
if (freeAimLock == LockType.Disabled)
{
KickStarter.playerInput.SetFreeAimLock (true);
}
else if (freeAimLock == LockType.Enabled)
{
KickStarter.playerInput.SetFreeAimLock (false);
}
}
if (IsUltimateFPS ())
{
return 0f;
}
if (doRunLock != PlayerMoveLock.NoChange)
{
KickStarter.playerInput.runLock = doRunLock;
}
}
if (player)
{
if (movePath)
{
player.SetLockedPath (movePath);
player.SetMoveDirectionAsForward ();
}
else if (player.GetPath ())
{
player.EndPath ();
}
if (doGravityLock == LockType.Enabled)
{
player.ignoreGravity = false;
}
else if (doGravityLock == LockType.Disabled)
{
player.ignoreGravity = true;
}
if (AllowHeadTurning ())
{
if (doHotspotHeadTurnLock == LockType.Disabled)
{
player.SetHotspotHeadTurnLock (true);
}
else if (doHotspotHeadTurnLock == LockType.Enabled)
//.........这里部分代码省略.........
开发者ID:WastNotWantNot,项目名称:WasteNotWantNot,代码行数:101,代码来源:ActionPlayerLock.cs
示例16: ShowGUI
public override void ShowGUI()
{
if (IsSingleLockMovement ())
{
doUpLock = (LockType) EditorGUILayout.EnumPopup ("Movement:", doUpLock);
}
else
{
doUpLock = (LockType) EditorGUILayout.EnumPopup ("Up movement:", doUpLock);
doDownLock = (LockType) EditorGUILayout.EnumPopup ("Down movement:", doDownLock);
doLeftLock = (LockType) EditorGUILayout.EnumPopup ("Left movement:", doLeftLock);
doRightLock = (LockType) EditorGUILayout.EnumPopup ("Right movement:", doRightLock);
}
if (IsInFirstPerson ())
{
freeAimLock = (LockType) EditorGUILayout.EnumPopup ("Free-aiming:", freeAimLock);
}
if (!IsUltimateFPS ())
{
doRunLock = (PlayerMoveLock) EditorGUILayout.EnumPopup ("Walk / run:", doRunLock);
doGravityLock = (LockType) EditorGUILayout.EnumPopup ("Affected by gravity?", doGravityLock);
movePath = (Paths) EditorGUILayout.ObjectField ("Move path:", movePath, typeof (Paths), true);
}
if (AllowHeadTurning ())
{
doHotspotHeadTurnLock = (LockType) EditorGUILayout.EnumPopup ("Hotspot head-turning?", doHotspotHeadTurnLock);
}
AfterRunningOption ();
}
开发者ID:WastNotWantNot,项目名称:WasteNotWantNot,代码行数:33,代码来源:ActionPlayerLock.cs
示例17: ShowGUI
public override void ShowGUI()
{
changeMovementMethod = EditorGUILayout.BeginToggleGroup ("Change movement method?", changeMovementMethod);
newMovementMethod = (MovementMethod) EditorGUILayout.EnumPopup ("Movement method:", newMovementMethod);
EditorGUILayout.EndToggleGroup ();
EditorGUILayout.Space ();
cursorLock = (LockType) EditorGUILayout.EnumPopup ("Cursor:", cursorLock);
inputLock = (LockType) EditorGUILayout.EnumPopup ("Input:", inputLock);
interactionLock = (LockType) EditorGUILayout.EnumPopup ("Interactions:", interactionLock);
menuLock = (LockType) EditorGUILayout.EnumPopup ("Menus:", menuLock);
movementLock = (LockType) EditorGUILayout.EnumPopup ("Movement:", movementLock);
cameraLock = (LockType) EditorGUILayout.EnumPopup ("Camera:", cameraLock);
triggerLock = (LockType) EditorGUILayout.EnumPopup ("Triggers:", triggerLock);
playerLock = (LockType) EditorGUILayout.EnumPopup ("Player:", playerLock);
saveLock = (LockType) EditorGUILayout.EnumPopup ("Saving:", saveLock);
AfterRunningOption ();
}
开发者ID:WastNotWantNot,项目名称:WasteNotWantNot,代码行数:20,代码来源:ActionSystemLock.cs
示例18: UnlockMovement
public void UnlockMovement(LockType type)
{
if ((MoveStates)CurrentState == MoveStates.moveLocked)
{
if (type == LockType.MovementLock)
{
_lockTime = Time.time;
}
else
{
_shiftLocked = false;
}
}
}
开发者ID:ryanadair009,项目名称:CMPS427,代码行数:15,代码来源:MovementFSM.cs
示例19: ToLockType
private static extern int ToLockType (Int16 value, out LockType rval);
开发者ID:Profit0004,项目名称:mono,代码行数:1,代码来源:NativeConvert.generated.cs
示例20: TryToLockType
public static bool TryToLockType (Int16 value, out LockType rval)
{
return ToLockType (value, out rval) == 0;
}
开发者ID:Profit0004,项目名称:mono,代码行数:4,代码来源:NativeConvert.generated.cs
注:本文中的LockType类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论