本文整理汇总了C#中OpenFileDialog.InitializeLifetimeService方法的典型用法代码示例。如果您正苦于以下问题:C# OpenFileDialog.InitializeLifetimeService方法的具体用法?C# OpenFileDialog.InitializeLifetimeService怎么用?C# OpenFileDialog.InitializeLifetimeService使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OpenFileDialog
的用法示例。
在下文中一共展示了OpenFileDialog.InitializeLifetimeService方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: browseButton_Click
void browseButton_Click(object sender, EventArgs e)
{
using (var openDialog = new OpenFileDialog())
{
openDialog.InitializeLifetimeService();
openDialog.Filter = "License files (*.xml)|*.xml|All files (*.*)|*.*";
openDialog.Title = "Select License file";
var dialogResult = StaThreadRunner.ShowDialogInSTA(openDialog.ShowDialog);
if (dialogResult == DialogResult.OK)
{
var licenseText = NonLockingFileReader.ReadAllTextWithoutLocking(openDialog.FileName);
try
{
LicenseVerifier.Verify(licenseText);
var license = LicenseDeserializer.Deserialize(licenseText);
if (LicenseExpirationChecker.HasLicenseExpired(license))
{
var message = "The license you provided has expired, select another file.";
Logger.Warn(message);
MessageBox.Show(this, message, "License expired", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return;
}
ResultingLicenseText = licenseText;
Close();
}
catch (Exception exception)
{
var message = $"An error occurred when parsing the license.\r\nMessage: {exception.Message}\r\nThe exception details have been appended to the log.";
Logger.Warn("Error parsing license", exception);
MessageBox.Show(this, message, "Error parsing license", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}