在我的 winphone 应用程序中,我遇到了一个奇怪的情况,我得到了一个System.IO.FileNotFoundException
与文件无关的代码。
我有一个管理延迟函数调用的类:
// Delayed function manager
namespace Test
{
public static class At
{
private readonly static TimerCallback timer =
new TimerCallback(At.ExecuteDelayedAction);
public static void Do(Action action, TimeSpan delay,
int interval = Timeout.Infinite)
{
var secs = Convert.ToInt32(delay.TotalMilliseconds);
new Timer(timer, action, secs, interval);
}
public static void Do(Action action, int delay,
int interval = Timeout.Infinite)
{
Do(action, TimeSpan.FromMilliseconds(delay), interval);
}
public static void Do(Action action, DateTime dueTime,
int interval = Timeout.Infinite)
{
if (dueTime < DateTime.Now) return;
else Do(action, dueTime - DateTime.Now, interval);
}
private static void ExecuteDelayedAction(object o)
{
(o as Action).Invoke();
}
}
}
还有一个管理 ProgressIndicator 状态的类:
namespace Test
{
public class Indicator
{
public DependencyObject ThePage;
public ProgressIndicator Progressor;
public Indicator(DependencyObject page)
{
ThePage = page;
Progressor = new ProgressIndicator();
SystemTray.SetProgressIndicator(ThePage, Progressor);
}
// If set(true) then set(false) in one second to remove ProgressIndicator
public void set(bool isOn)
{
Progressor.IsIndeterminate = Progressor.IsVisible = isOn; // Exception happens on this line
if (isOn) At.Do(delegate { this.set(false); }, 1000);
}
}
}
当我尝试set(true)
在代码中运行方法时,出现以下异常:
An exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.ni.dll and wasn't handled before a managed/native boundary
A first chance exception of type 'System.UnauthorizedAccessException' occurred in System.Windows.ni.dll
为什么会发生这种情况,如何解决?