本文整理汇总了C#中ValueSet.TryGetValue方法的典型用法代码示例。如果您正苦于以下问题:C# ValueSet.TryGetValue方法的具体用法?C# ValueSet.TryGetValue怎么用?C# ValueSet.TryGetValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ValueSet
的用法示例。
在下文中一共展示了ValueSet.TryGetValue方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DestructMessage
const int RPC_S_SERVER_UNAVAILABLE = -2147023174; // 0x800706BA
public static void DestructMessage(ValueSet valueSet, out string tag, out string content)
{
object tagObj;
valueSet.TryGetValue(AudioRpc.MessageTag, out tagObj);
object contentObj;
valueSet.TryGetValue(AudioRpc.MessageContent, out contentObj);
tag = tagObj as string ?? string.Empty;
content = contentObj as string ?? string.Empty;
}
示例2: HandleNotification
void HandleNotification(ValueSet valueSet)
{
//Debug.WriteLine("BackgroundAudioRun.HandleNotification() " + _id);
if (_completionSource.Task.IsCompleted)
return;
try
{
object idValue;
if (valueSet.TryGetValue(BackgroundNotificationType.Id, out idValue))
{
var id = idValue as Guid?;
if (id.HasValue && _appId.HasValue && id.Value != _appId.Value)
{
Debug.WriteLine("BackgroundAudioRun.HandleNotification() " + _id + " != " + id.Value);
return;
}
}
else
{
Debug.WriteLine("BackgroundAudioRun.HandleNotification() no id " + _id);
return;
}
Guid? appId = null;
var isStart = false;
var isStop = false;
foreach (var kv in valueSet)
{
//Debug.WriteLine(" f->b {0}: {1}", kv.Key, kv.Value);
if (null == kv.Key)
{
Debug.WriteLine("*** BackgroundAudioRun.HandleNotification() null key");
continue; // This does happen. It shouldn't, but it does.
}
BackgroundNotificationType type;
if (!Enum.TryParse(kv.Key, true, out type))
continue;
switch (type)
{
case BackgroundNotificationType.Start:
case BackgroundNotificationType.Resume:
isStart = true;
break;
case BackgroundNotificationType.Stop:
case BackgroundNotificationType.Suspend:
isStop = true;
break;
case BackgroundNotificationType.Ping:
if (_appId.HasValue)
_foregroundNotifier.Notify(BackgroundNotificationType.Pong, kv.Value);
break;
case BackgroundNotificationType.Pong:
{
var challenge = kv.Value as Guid?;
if (challenge.HasValue && challenge.Value == _challengeToken.Value)
_challengeCompletionSource.TrySetResult(challenge.Value);
}
break;
case BackgroundNotificationType.Smtc:
if (_appId.HasValue)
{
SystemMediaTransportControlsButton button;
if (Enum.TryParse((string)kv.Value, true, out button))
{
var mediaPlayerManager = _mediaPlayerManager;
if (null != mediaPlayerManager)
HandleSmtcButton(mediaPlayerManager, button);
}
}
break;
case BackgroundNotificationType.Memory:
NotifyForegroundMemory();
break;
case BackgroundNotificationType.Gc:
var task = Task.Run(() =>
{
MemoryDiagnostics.DumpMemory();
Debug.WriteLine("Force GC: {0:F2}MiB", GC.GetTotalMemory(false).BytesToMiB());
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
Debug.WriteLine("Forced GC: {0:F2}MiB", GC.GetTotalMemory(true).BytesToMiB());
MemoryDiagnostics.DumpMemory();
NotifyForegroundMemory();
});
//.........这里部分代码省略.........
示例3: HandleTileEventAsync
public async Task HandleTileEventAsync(ValueSet message)
{
//Check if we are currently handling another tile event
if (this._backgroundTileEventTaskSource != null)
{
object eventType;
if (message.TryGetValue("Type", out eventType) &&
eventType as string == "TileButtonPressedEvent")
{
//If its a tile button pressed event, we do nothing
return;
}
else
{
//For other events we wait till it has finished
await this._backgroundTileEventTaskSource.Task;
}
}
this._backgroundTileEventTaskSource = new TaskCompletionSource<object>();
bool eventHandled = BackgroundTileEventHandler.Instance.HandleTileEvent(message);
if (eventHandled == false)
this._backgroundTileEventTaskSource.SetResult(null);
await this._backgroundTileEventTaskSource.Task;
this._backgroundTileEventTaskSource = null;
}