本文整理汇总了C#中Windows.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# Windows.Dispose方法的具体用法?C# Windows.Dispose怎么用?C# Windows.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Windows
的用法示例。
在下文中一共展示了Windows.Dispose方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReencodePhotoAsync
private async Task<Windows.Storage.StorageFile> ReencodePhotoAsync(
Windows.Storage.Streams.IRandomAccessStream stream,
Windows.Storage.FileProperties.PhotoOrientation photoRotation)
{
Windows.Storage.Streams.IRandomAccessStream inputStream = null;
Windows.Storage.Streams.IRandomAccessStream outputStream = null;
Windows.Storage.StorageFile photoStorage = null;
try
{
inputStream = stream;
var decoder = await Windows.Graphics.Imaging.BitmapDecoder.CreateAsync(inputStream);
photoStorage = await Windows.Storage.KnownFolders.PicturesLibrary.CreateFileAsync(PHOTO_FILE_NAME, Windows.Storage.CreationCollisionOption.GenerateUniqueName);
outputStream = await photoStorage.OpenAsync(Windows.Storage.FileAccessMode.ReadWrite);
outputStream.Size = 0;
var encoder = await Windows.Graphics.Imaging.BitmapEncoder.CreateForTranscodingAsync(outputStream, decoder);
var properties = new Windows.Graphics.Imaging.BitmapPropertySet();
properties.Add("System.Photo.Orientation",
new Windows.Graphics.Imaging.BitmapTypedValue(photoRotation, Windows.Foundation.PropertyType.UInt16));
await encoder.BitmapProperties.SetPropertiesAsync(properties);
await encoder.FlushAsync();
}
finally
{
if (inputStream != null)
{
inputStream.Dispose();
}
if (outputStream != null)
{
outputStream.Dispose();
}
}
return photoStorage;
}
示例2: OnNTPTimeReceived
/// <summary>
/// Event hander when receiving response from the ntp server.
/// </summary>
/// <param name="socket">The udp socket object which triggered this event </param>
/// <param name="eventArguments">event information</param>
void OnNTPTimeReceived(Windows.Networking.Sockets.DatagramSocket socket, Windows.Networking.Sockets.DatagramSocketMessageReceivedEventArgs eventArguments)
{
int currentRTT = (int)ntpResponseMonitor.ElapsedMilliseconds;
Debug.WriteLine($"NtpSync: current RTT {currentRTT}");
ntpResponseMonitor.Stop();
if (currentNtpQueryCount < MaxNtpRTTProbeQuery)
{
//we only trace 'min' RTT within the RTT probe attempts
if (minNtpRTT == -1 || minNtpRTT > currentRTT)
{
minNtpRTT = currentRTT;
if (minNtpRTT == 0)
minNtpRTT = 1; //in case we got response so fast, consider it to be 1ms.
}
averageNtpRTT = (averageNtpRTT * (currentNtpQueryCount - 1) + currentRTT) / currentNtpQueryCount;
if (averageNtpRTT < 1)
{
averageNtpRTT = 1;
}
RunOnUiThread(() =>
{
ntpQueryTimer.Stop();
ntpRTTIntervalTimer.Start();
});
return;
}
//if currentRTT is good enough, e.g.: closer to minRTT, then, we don't have to continue to query.
if (currentRTT > (averageNtpRTT + minNtpRTT) / 2)
{
RunOnUiThread(() =>
{
ntpQueryTimer.Stop();
ntpRTTIntervalTimer.Start();
});
return;
}
byte[] ntpData = new byte[48];
eventArguments.GetDataReader().ReadBytes(ntpData);
//Offset to get to the "Transmit Timestamp" field (time at which the reply
//departed the server for the client, in 64-bit timestamp format."
const byte serverReplyTime = 40;
//Get the seconds part
ulong intPart = BitConverter.ToUInt32(ntpData, serverReplyTime);
//Get the seconds fraction
ulong fractPart = BitConverter.ToUInt32(ntpData, serverReplyTime + 4);
//Convert From big-endian to little-endian
intPart = SwapEndianness(intPart);
fractPart = SwapEndianness(fractPart);
ulong milliseconds = (intPart * 1000) + ((fractPart * 1000) / 0x100000000L);
RunOnUiThread(() =>
{
OnNTPTimeAvailable?.Invoke((long)milliseconds + currentRTT / 2);
});
socket.Dispose();
ReportNtpSyncStatus(true, currentRTT);
}