在我的winphone應用程序中,我有一個奇怪的情況,我得到System.IO.FileNotFoundException
代碼中沒有任何與文件相關的代碼。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
爲什麼會發生這種情況,怎麼可能這是固定的?
如果您只是在調試器中看到異常(但不會中斷執行),那麼不用擔心,它只是Framework解析程序集的方式。 –
堆棧跟蹤在解決這樣的問題時總是有用的。 –
@Adriano,它不僅僅在調試器中,ProgressIndicator實際上並沒有消散,所以程序無法正常工作。 – Anton