I want an auto logoff feature in my WPF application and have implemented it with hooks. However whenever the mouse is over the application, the performance freezes, degrades and becomes unbearably unresponsive. Once the mouse is off the window performance goes back to normal. If I turn the auto logoff off, performance is fine always, so it's definitely this causing it. Any idea how to do it different to avoid this?
private void InitializeAutoLogoffFeature()
{
//var windowSpecificOSMessageListener = HwndSource.FromHwnd(new WindowInteropHelper(this).Handle);
//if (windowSpecificOSMessageListener != null)
// windowSpecificOSMessageListener.AddHook(CallBackMethod);
//AutoLogOffHelper.LogOffTime = _viewModel.logOffTime;
//AutoLogOffHelper.MakeAutoLogOffEvent += AutoLogOffHelper_MakeAutoLogOffEvent;
//AutoLogOffHelper.StartAutoLogoffOption();
AutoLogOffHelper
}
private static IntPtr CallBackMethod(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
{
try
{
// Listening OS message to test whether it is a user activity
if ((msg >= 0x0200 && msg <= 0x020A) || (msg <= 0x0106 && msg >= 0x00A0) || msg == 0x0021)
{
AutoLogOffHelper.ResetLogoffTimer();
}
else
{
// For debugging purpose
// If this auto logoff does not work for some user activity, you can detect the integer code of that activity using the following line.
//Then All you need to do is adding this integer code to the above if condition.
Debug.WriteLine(msg.ToString());
}
}
catch (Exception ex)
{
MessageHelper.LogError(ex);
}
return IntPtr.Zero;
}
class AutoLogOffHelper
{
static System.Windows.Forms.Timer _timer;
public static int LogOffTime { get; set; }
public delegate void MakeAutoLogOff();
static public event MakeAutoLogOff MakeAutoLogOffEvent;
static public void StartAutoLogoffOption()
{
System.Windows.Interop.ComponentDispatcher.ThreadIdle += DispatcherQueueEmptyHandler;
}
static void _timer_Tick(object sender, EventArgs e)
{
if (_timer == null) return;
System.Windows.Interop.ComponentDispatcher.ThreadIdle -= DispatcherQueueEmptyHandler;
_timer.Stop();
_timer = null;
if (MakeAutoLogOffEvent != null)
{
MakeAutoLogOffEvent();
}
}
static void DispatcherQueueEmptyHandler(object sender, EventArgs e)
{
if (_timer == null)
{
_timer = new System.Windows.Forms.Timer
{
Interval = LogOffTime * 60 * 1000
};
_timer.Tick += _timer_Tick;
_timer.Enabled = true;
}
else if (_timer.Enabled == false)
{
_timer.Enabled = true;
}
}
static public void ResetLogoffTimer()
{
if (_timer == null) return;
_timer.Enabled = false;
_timer.Enabled = true;
}
}
Try taking your debug.writeline out - It's very slow and since you might be dealing with a lot of events, it could easily be the problem.
Failing that, have you tried using the profiler to see what's eating up resources?
Related
In my legacy project I've a treeview and an OnClick event binded on treeview leafs. Basically each time I choose a leaf, I get the node type and I apply a template into a control such:
gridDati.Template = Resources["tmplBit"] as ControlTemplate;
The "tmplBit" is a DataTemplate with several columns. All works fine but sometimes when I have 20 columns and 30/40 records, it takes time (4/5 sec) while applying the chosen template.
I would like to show a waiting message, or something like that but I cannot find how. I've already a window that show a waiting message, I tried to use as:
var aboutBox = new winWaitingMessage(Global.LM.T("#_3261_Inizio export"));
aboutBox.Show();
// Template?
gridDati.Template = Resources["tmplBit"] as ControlTemplate;
aboutBox.Close();
but the box is closed immediately, so I cannot find an event that tell me when the template is applied and rendered. Any hints?
you can use task
[DllImport("user32.dll", CharSet = CharSet.Auto)]
static extern IntPtr FindWindow(IntPtr hwnd, string title);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
static extern int PostMessage(IntPtr hwnd, int msg, uint wParam, uint lParam);
public const int WM_CLOSE = 0x10;
public const int WM_KEYDOWN = 0x0100;
public const int WM_KEYUP = 0x0101;
public const int VK_RETURN = 0x0D;
private void Button_Click(object sender, RoutedEventArgs e)
{
Task task1 = new Task(() =>
{
gridDati.Template = Resources["tmplBit"] as ControlTemplate;
});
task1.Start();
Task cwt = task1.ContinueWith(t=>
{
FindAndKillWindow("Warning");
});
MessageBox.Show("Waiting...", "Warning");
}
private static void FindAndKillWindow(string title)
{
IntPtr ptr = FindWindow(IntPtr.Zero, title);
if (ptr != IntPtr.Zero)
{
int ret = PostMessage(ptr, WM_CLOSE, 0, 0);
ptr = FindWindow(IntPtr.Zero, title);
if (ptr != IntPtr.Zero)
{
PostMessage(ptr, WM_KEYDOWN, VK_RETURN, 0);
PostMessage(ptr, WM_KEYUP, VK_RETURN, 0);
}
}
}
The framework provides no such event but you could handle the Loaded event for an element in the template and close the window when this event occurs, e.g.:
gridDati.Template = Resources["tmplBit"] as ControlTemplate;
gridDati.ApplyTemplate();
FrameworkElement fe = gridDati.Template.FindName("YourElement", gridDati) as FrameworkElement;
if (fe == null)
{
aboutBox.Close();
}
else
{
void Fe_Loaded(object sender, RoutedEventArgs e)
{
aboutBox.Close();
fe.Loaded -= Fe_Loaded;
}
fe.Loaded += Fe_Loaded;
}
XAML:
<ControlTemplate x:Key="tmplBit">
...
<Button x:Name="YourElement" ... />
Edit: If you don't want to or can't use a local function for whatever reason, you could use a lambda expression to achieve the same thing:
...
else
{
RoutedEventHandler loadedHandler = null;
loadedHandler = (s, e) =>
{
aboutBox.Close();
fe.Loaded -= loadedHandler;
};
fe.Loaded += loadedHandler;
}
I am using RadTileView in my project, and by default the Tile Drag and Drop is enabled when they are in restored state
,
but I can't achieve the same functionality when 1 tile is in maximized state and all others are in minimized state
,
I think that Telerik hasn't provided this functionality in their RadTileView control. What would be the best way to achieve this, or is it possible or not?
After searching through different blogs, I came to know that this functionality is not available in Telerik Tile view out of the box, but they have added it in their wish list, You can vote for this feature here http://www.telerik.com/support/pits.aspx#/public/silverlight/2449
However as a work arround I have implemented a Behavior my self for RadTileView, which will do the required task.
public class RadTilesDragDropBehavior : Behavior<RadTileView>
{
private RadTileViewItem draggingTile { get; set; }
public TileViewDragDropBehavior()
{
// Insert code required on object creation below this point.
}
protected override void OnAttached()
{
base.OnAttached();
// Insert code that you would want run when the Behavior is attached to an object.
DragDropManager.AddDragInitializeHandler(AssociatedObject, OnDragInitialize);
DragDropManager.AddDragDropCompletedHandler(AssociatedObject, OnDragAndDropCompleted);
AssociatedObject.PreviewDragOver += MyTileView_PreviewDragOver;
}
private void OnDragInitialize(object sender, DragInitializeEventArgs args)
{
var tileView = sender as RadTileView;
var tileViewItem = args.OriginalSource as RadTileViewItem;
Point pt = Util.CorrectGetPosition((RadTileView)sender);
HitTestResult result = VisualTreeHelper.HitTest(AssociatedObject, pt);
if (result != null)
{
DependencyObject obj = result.VisualHit.ParentOfType<RadFluidContentControl>();
if (obj != null)
{
//trying to drag from Tile content area, not allowed.
return;
}
}
if (tileViewItem != null && tileView != null && tileView.MaximizedItem != null)
{
args.Data = tileViewItem;
var draggingImage = new Image
{
Source = new Telerik.Windows.Media.Imaging.RadBitmap(tileViewItem).Bitmap,
Width = tileViewItem.RestoredWidth,
Height = tileViewItem.RestoredHeight
};
if (tileView.MaximizedItem == tileViewItem)
{
args.DragVisualOffset = new Point(args.RelativeStartPoint.X - 50, args.RelativeStartPoint.Y-55);
}
args.DragVisual = draggingImage;
tileViewItem.Opacity = 0;
args.AllowedEffects = DragDropEffects.Move;
args.Handled = true;
// keep a copy of dragging tile
draggingTile = tileViewItem;
}
}
private void OnDragAndDropCompleted(object sender, DragDropCompletedEventArgs args)
{
if (args.OriginalSource.GetType() == typeof(RadTileViewItem))
{
if (AssociatedObject.MaximizedItem != null)
{
Point pt = Util.CorrectGetPosition((RadTileView)sender);
HitTestResult result = VisualTreeHelper.HitTest(AssociatedObject, pt);
if (result != null)
{
DependencyObject obj = result.VisualHit.ParentOfType<RadTileViewItem>();
if (obj != null)
{
((RadTileViewItem)obj).Position = draggingTile.Position;
draggingTile.Opacity = 100;
}
else
{
draggingTile.Opacity = 100;
}
}
else
{
draggingTile.Opacity = 100;
}
}
}
}
private void MyTileView_PreviewDragOver(object sender, System.Windows.DragEventArgs e)
{
FrameworkElement container = sender as FrameworkElement;
if (AssociatedObject.MaximizedItem != null)
{
if (container == null)
{
return;
}
double tolerance = 60;
double verticalPos = Util.CorrectGetPosition((RadTileView)container).Y;
double offset = 20;
ScrollViewer scrollViewer = AssociatedObject.FindChildByType<ScrollViewer>();
if (verticalPos < tolerance) // Top of visible list?
{
scrollViewer.ScrollToVerticalOffset(scrollViewer.VerticalOffset - offset); //Scroll up.
}
else if (verticalPos > container.ActualHeight - tolerance) //Bottom of visible list?
{
scrollViewer.ScrollToVerticalOffset(scrollViewer.VerticalOffset + offset); //Scroll down.
}
}
}
protected override void OnDetaching()
{
base.OnDetaching();
// Insert code that you would want run when the Behavior is removed from an object.
DragDropManager.RemoveDragInitializeHandler(AssociatedObject, OnDragInitialize);
DragDropManager.RemoveDragDropCompletedHandler(AssociatedObject, OnDragAndDropCompleted);
AssociatedObject.PreviewDragOver -= MyTileView_PreviewDragOver;
}
}
public static class Util
{
public static Point CorrectGetPosition(Visual relativeTo)
{
Win32Point w32Mouse = new Win32Point();
GetCursorPos(ref w32Mouse);
return relativeTo.PointFromScreen(new Point(w32Mouse.X, w32Mouse.Y));
}
[StructLayout(LayoutKind.Sequential)]
internal struct Win32Point
{
public Int32 X;
public Int32 Y;
};
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
internal static extern bool GetCursorPos(ref Win32Point pt);
};
XAML would be like this
<telerik:RadTileView x:Name="MyTileView" ItemsSource={Binding TileItems}>
<i:Interaction.Behaviors>
<behaviors:RadTilesDragDropBehavior/>
</i:Interaction.Behaviors>
</telerik:RadTileView>
I have a WinForms application that is calling a business class method that performs some heavy duty action taking about 5 seconds for each call. The main form calls this method in a loop. This loop can run from 10 times to maybe up to 10 thousand times.
The WinForms application sends a parameter to the business class and has an area to display the time taken for each method call and what the value returned by the method. How do I inform my main window and update a text area in the main winform with what the method has returned for each call?
Currently the data comes all at once after all the threads have finished. Is there a way to update the UI for all the iterations of the loop once the each call is done? I don't mind if it is done sequentially also.
The FORM
HeavyDutyClass hd;
public Form1()
{
InitializeComponent();
hd = new HeavyDutyClass();
}
//BUTTON CLICK
private void Start_Click(object sender, EventArgs e)
{
int filecount = 5000; //BAD - opening 5000 threads! Any other approach?
hd.FileProcessed += new EventHandler(hd_FileProcessed);
var threads = new Thread[filecount];
for (int i = 0; i < filecount; i++)
{
threads[i] = new Thread(() => { hd.LongRunningMethod(); });
threads[i].Start();
}
}
//BUSINESS CLASS EVENT THAT FIRES WHEN BUSINESS METHOD COMPELTES
void hd_FileProcessed(object sender, EventArgs e)
{
if (dgv.InvokeRequired)
{
dgv.Invoke((MethodInvoker)delegate { UpdateGrid(); });
}
}
private void UpdateGrid()
{
dgv.Rows.Add(1);
int i = dgv.Rows.Count;
dgv.Rows [ i-1].Selected = true;
dgv.FirstDisplayedScrollingRowIndex = i - 1;
}
The business HeavyDuty class
public event EventHandler FileProcessed;
public HeavyDutyClass()
{
}
protected virtual void OnMyEvent(EventArgs e)
{
if (FileProcessed != null)
{
FileProcessed(this, e);
}
}
public bool LongRunningMethod()
{
for (double i = 0; i < 199990000; i++)
{
//time consuming loop
}
OnMyEvent(EventArgs.Empty);
return true;
}
Add a Winforms Project, Drop a Label Control on the Form , Copy-Paste this code and Hit F5
[EDIT]: Updated with the business class comment from the user
NB: My form class is named Form3. You may have to change your Program.cs or vice-versa.
using System.ComponentModel;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public class BusinessClass
{
public int MyFunction(int input)
{
return input+10;
}
}
public partial class Form3 : Form
{
private BackgroundWorker _worker;
BusinessClass _biz = new BusinessClass();
public Form3()
{
InitializeComponent();
InitWorker();
}
private void InitWorker()
{
if (_worker != null)
{
_worker.Dispose();
}
_worker = new BackgroundWorker
{
WorkerReportsProgress = true,
WorkerSupportsCancellation = true
};
_worker.DoWork += DoWork;
_worker.RunWorkerCompleted += RunWorkerCompleted;
_worker.ProgressChanged += ProgressChanged;
_worker.RunWorkerAsync();
}
void DoWork(object sender, DoWorkEventArgs e)
{
int highestPercentageReached = 0;
if (_worker.CancellationPending)
{
e.Cancel = true;
}
else
{
double i = 0.0d;
int junk = 0;
for (i = 0; i <= 199990000; i++)
{
int result = _biz.MyFunction(junk);
junk++;
// Report progress as a percentage of the total task.
var percentComplete = (int)(i / 199990000 * 100);
if (percentComplete > highestPercentageReached)
{
highestPercentageReached = percentComplete;
// note I can pass the business class result also and display the same in the LABEL
_worker.ReportProgress(percentComplete, result);
_worker.CancelAsync();
}
}
}
}
void RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
if (e.Cancelled)
{
// Display some message to the user that task has been
// cancelled
}
else if (e.Error != null)
{
// Do something with the error
}
}
void ProgressChanged(object sender, ProgressChangedEventArgs e)
{
label1.Text = string.Format("Result {0}: Percent {1}",e.UserState, e.ProgressPercentage);
}
}
}
With this you can achieve Cancel functionality also very easily.
Observe that during initialisation, I set the WorkerSupportsCancellation = true & then I check for _worker.CancellationPending in the DoWork. So, if you want to cancel the process by a Cancel Button click, then you will write this code in the button handler- _worker.CancelAsync();
Every time timer ticks the application keep on using extra memory.
How to dispose the handle in GetActeWindowTitle() and window2?
How should i manage the memory usage for this?
my Code :
public partial class Window1 : Window
{
Window2 window2 ;
System.Windows.Forms.Timer timer1;
public Window1()
{
InitializeComponent();
timer1 = new Timer();
timer1.Interval = 900000;
timer1.Tick += new EventHandler(timer1Tick);
timer1.Start();
}
private void timer1Tick( object Sender, EventArgs e )
{
window2 = new window2Window();
if (((GetActeWindowTitle().IndexOf("Outlook") != -1) ||
(GetActeWindowTitle().IndexOf("Word") != -1)))
{
window2.Close();
}
else
{
window2.Show();
window2.Topmost = true;
}
}
private string GetActeWindowTitle()
{
const int nChars = 256;
IntPtr handle = IntPtr.Zero;
StringBuilder Buff = new StringBuilder(nChars);
handle = GetForegroundWindow();
if (GetWindowText(handle, Buff, nChars) > 0)
{
return Buff.ToString();
}
return null;
}
}
Maybe by releasing the memory that gets allocated from that Interop call referenced in the IntPtr.
Try this after using you handle in GetActeWindowTitle():
Marshal.FreeCoTaskMem(handle);
Why create new window2Window only to close it?
// window2 = new window2Window();
if (((GetActeWindowTitle().IndexOf("Outlook") != -1) ||
(GetActeWindowTitle().IndexOf("Word") != -1)))
{
// window2.Close();
}
else
{
window2 = new window2Window();
window2.Show();
window2.Topmost = true;
}
I've written a WPF application that uses many Frame controls to view camera feeds. When deployed, it crashes pretty randomly (anywhere from 2 hours to 16+ hours), and I see these in the event log, consecutively:
System.AccessViolationException:
Attempted to read or write protected
memory. This is often an indication
that other memory is corrupt. at
MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG&
msg) at
System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame
frame) at
System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame
frame) at
System.Windows.Threading.Dispatcher.Run()
at
System.Windows.Application.RunDispatcher(Object
ignore) at
System.Windows.Application.RunInternal(Window
window) at
System.Windows.Application.Run(Window
window) at
System.Windows.Application.Run() at
Status_Station_client.MainClass.Main()
Faulting application status station
client.exe, version 1.0.0.0, stamp
4ad0faa5, faulting module msvfw32.dll,
version 5.1.2600.2180, stamp 41109753,
debug? 0, fault address 0x00002642.
Any ideas on how to track this down? The web pages do contain ActiveX controls, so a first guess is there's a problem there.
I haven't been able to trace this in Debug mode. Another thing I have thought of trying is swallowing the exception from the navigation call, but am unsure if this is a wise thing to do:
try
{
if (Frame1 != null)
Frame1.Source = new Uri(uriWithResolution);
}
catch (AccessViolationException ex)
{
// log message
}
EDIT: Here's some more source code, I'm stumped as to where the error is (i.e. where the exception is being thrown)
MatrixView.cs:
public partial class MatrixView : Window
{
System.Timers.Timer timer;
int pageNumber = 0;
IEnumerable<List<CameraInfo>> _cameraList;
GlobalSettings _globalSettings;
Screen _screen;
public MatrixView(List<CameraInfo> cameras, int pageFlipInterval, int camerasPerPage, GlobalSettings globalSettings, Screen screen)
{
InitializeComponent();
_globalSettings = globalSettings;
_screen = screen;
_cameraList = Partition<CameraInfo>(cameras, camerasPerPage);
this.Dispatcher.UnhandledException += new DispatcherUnhandledExceptionEventHandler(Dispatcher_UnhandledException);
displayCameras();
timer = new System.Timers.Timer(pageFlipInterval * 1000); // interval (in seconds) * 1000 ms / s
timer.Elapsed += new ElapsedEventHandler(timer_Elapsed);
timer.Enabled = true;
this.KeyUp += new System.Windows.Input.KeyEventHandler(MatrixView_KeyUp);
if (globalSettings.FullScreenOnLoad)
{
this.WindowStyle = WindowStyle.None;
}
}
void MatrixView_KeyUp(object sender, System.Windows.Input.KeyEventArgs e)
{
if (this.WindowStyle == WindowStyle.None)
{
if (e.Key == Key.F11 || e.Key == Key.Escape)
{
this.WindowStyle = WindowStyle.SingleBorderWindow;
}
}
else
{
if (e.Key == Key.F11)
{
this.WindowStyle = WindowStyle.None;
}
}
this.WindowState = WindowState.Maximized;
}
void timer_Elapsed(object sender, ElapsedEventArgs e)
{
this.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new ThreadStart(delegate()
{
displayCameras();
}));
}
void Dispatcher_UnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
{
EventLog.WriteEntry("Matrix Monitor", string.Format("Unhandled exception from Matrix Dispatcher\r\nMessage: {0}\r\nSource: {1}\r\nInnerException: {2}\r\nStack Trace: {3}\r\nFull String: {4}", e.Exception.Message, e.Exception.Source, e.Exception.InnerException, e.Exception.StackTrace, e.Exception.ToString()));
e.Handled = true;
}
private void displayCameras()
{
foreach (var child in uniformGrid1.Children)
{
FrameTimer c = child as FrameTimer;
if (c != null)
{
c.Dispose();
c = null;
}
}
GC.Collect();
GC.WaitForPendingFinalizers();
uniformGrid1.Children.Clear();
List<CameraInfo> camerasInPage = _cameraList.ElementAt(pageNumber);
int numCameras = camerasInPage.Count;
int sqrtOfCameras = (int) Math.Sqrt(numCameras);
double height = _screen.Bounds.Height / sqrtOfCameras;
double width = _screen.Bounds.Width / sqrtOfCameras;
foreach (CameraInfo camera in camerasInPage)
{
uniformGrid1.Children.Add(new FrameTimer(camera, _globalSettings, height, width));
}
pageNumber++;
if (pageNumber >= _cameraList.Count<List<CameraInfo>>())
{
pageNumber = 0;
}
}
public static IEnumerable<List<T>> Partition<T>(IList<T> source, int size)
{
int remainder = source.Count % size == 0 ? 0 : 1;
for (int i = 0; i < (source.Count / size) + remainder; i++)
yield return new List<T>(source.Skip(size * i).Take(size));
}
}
FrameTimer.cs:
public partial class FrameTimer : UserControl, IDisposable
{
System.Timers.Timer timer;
string _uri;
string _noImageUrl;
bool? _successState = null;
GlobalSettings _globalSettings;
CameraInfo _camera;
Ping ping;
double _height;
double _width;
public FrameTimer(CameraInfo camera, GlobalSettings globalSettings, double height, double width)
{
InitializeComponent();
_noImageUrl = AppDomain.CurrentDomain.BaseDirectory + "noImage.jpg";
_globalSettings = globalSettings;
_camera = camera;
_height = height;
_width = width;
_uri = string.Format("http://{0}:{1}/LiveView.aspx?camera={2}", globalSettings.ServerIPAddress, globalSettings.ServerPort, camera.camName);
this.Dispatcher.UnhandledException += new DispatcherUnhandledExceptionEventHandler(Dispatcher_UnhandledException);
setUrl();
timer = new System.Timers.Timer(_globalSettings.PingInterval * 1000);
timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_Elapsed);
timer.Enabled = true;
}
void Dispatcher_UnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
{
EventLog.WriteEntry("Matrix Monitor", string.Format("Unhandled exception from Frame Dispatcher\r\nMessage: {0}\r\nSource: {1}\r\nInnerException: {2}\r\nStack Trace: {3}\r\nFull String: {4}", e.Exception.Message, e.Exception.Source, e.Exception.InnerException, e.Exception.StackTrace, e.Exception.ToString()));
e.Handled = true;
}
void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
this.Dispatcher.BeginInvoke(DispatcherPriority.Send, new ThreadStart(delegate()
{
setUrl();
}));
}
private void setUrl()
{
ping = new Ping();
ping.PingCompleted += new PingCompletedEventHandler(ping_PingCompleted);
videoChecks checks = new videoChecks();
string ipAddressToUse = checks.isIPInternal(_camera.camIP) ? _camera.camIP : _camera.camExtIP;
ping.SendAsync(ipAddressToUse, 1000, null);
}
void ping_PingCompleted(object sender, PingCompletedEventArgs e)
{
try
{
if (e.Reply.Status == IPStatus.Success)
{
if (_successState == null || _successState == false)
{
_successState = true;
string uriWithResolution = string.Format("{0}&res={1}x{2}&header=0", _uri, (int)_width, (int)_height);
if (Frame1 != null)
Frame1.Source = new Uri(uriWithResolution);
}
}
else
{
if (_successState == null || _successState == true)
{
_successState = false;
Image1.Source = new BitmapImage(new Uri(_noImageUrl));
}
}
}
catch (ObjectDisposedException ex)
{
Dispose();
}
finally
{
((IDisposable)sender).Dispose();
}
}
#region IDisposable Members
public void Dispose()
{
if (timer != null)
{
timer.Elapsed -= new System.Timers.ElapsedEventHandler(timer_Elapsed);
timer.Enabled = false;
timer.Dispose();
timer = null;
}
Frame1.Source = null;
if (ping != null)
{
ping.PingCompleted -= new PingCompletedEventHandler(ping_PingCompleted);
((IDisposable)ping).Dispose();
ping = null;
}
}
#endregion
}
If you look at the faulting module at the bottom your stacktrace, you will see msvfw32.dll. This is not a DLL used by WPF, so I assume it's coming from some active-x within a web page you are loading. I'm even more convinced of that due to your code implying something dealing with cameras/video and msvfw32 deals with video (its very old too!!). It's showing up in the Dispatcher loop because the Dispatcher also handles a Win32 message loop, that is ultimately used by the alleged activex.
Also, try checking for the exception here, maybe you can set the argument Handled=true