Questo blog è stato creato come diario persoanle

Questo blog è realizzato come diario personale,per provare le mie
capacità di programmazione e altro

martedì 2 marzo 2010

Application.DoEvents su WPF

using System;

using System.Windows;

using System.Windows.Threading;

namespace Sheva.Windows

{

///

/// Designates a Windows Presentation Foundation application model with added functionalities.

///

public class WpfApplication : Application

{

private static DispatcherOperationCallback exitFrameCallback = new

DispatcherOperationCallback(ExitFrame);

///

/// Processes all UI messages currently in the message queue.

///

public static void DoEvents()

{

// Create new nested message pump.

DispatcherFrame nestedFrame = new DispatcherFrame();

// Dispatch a callback to the current message queue, when getting called,

// this callback will end the nested message loop.

// note that the priority of this callback should be lower than the that of UI event messages.

DispatcherOperation exitOperation = Dispatcher.CurrentDispatcher.BeginInvoke(

DispatcherPriority.Background, exitFrameCallback, nestedFrame);

// pump the nested message loop, the nested message loop will

// immediately process the messages left inside the message queue.

Dispatcher.PushFrame(nestedFrame);

// If the "exitFrame" callback doesn't get finished, Abort it.

if (exitOperation.Status != DispatcherOperationStatus.Completed)

{

exitOperation.Abort();

}

}

private static Object ExitFrame(Object state)

{

DispatcherFrame frame = state as DispatcherFrame;

// Exit the nested message loop.

frame.Continue = false;

return null;

}

}

}

Nessun commento: