Új hozzászólás Aktív témák
-
x007
tag
Jaaaa, WPF-ben nincsen gyári DoEvents, viszont van workaround:
private void button1_Click(object sender, RoutedEventArgs e)
{
button1.IsEnabled = false;
WpfApplication.DoEvents();
Thread.Sleep(3000);
button1.IsEnabled = true;
}
/// <summary>
/// Designates a Windows Presentation Foundation application model with added functionalities.
/// </summary>
public class WpfApplication : Application
{
private static DispatcherOperationCallback exitFrameCallback = new
DispatcherOperationCallback(ExitFrame);
/// <summary>
/// Processes all UI messages currently in the message queue.
/// </summary>
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;
}
}Megjegyzem, hogy ez továbbra se fogja teljes mértékig megoldani a problémát, mert az ablak ugyanúgy meg fog fagyni a DB kapcsolat tesztelésekor. (WinForms esetén is így lenne) Szóval mindenképpen javaslom a BackGroundWorker használatát.
Új hozzászólás Aktív témák
● ha kódot szúrsz be, használd a PROGRAMKÓD formázási funkciót!
- Dell Latitude 5320 -60% "Kis Gamer" Üzleti Profi Ultrabook 13,3" i5-1145G7 16/512 FHD IRIS Xe
- Dobozos DELL Inspiron 16 Fémházas Multimédiás Laptop 16" -40% Ryzen 7 8840U 8mag 16/1TB FHD+ IPS
- Csőtörés bemérés - Csőtörés Javítás Szakszerűen
- Professzionális vízszerelés 0-24 akár azonnali kiszállással
- Fiorenzato AllGround eladó
- Apple iPhone 14 Pro / Gyárifüggetlen / 128GB / 12Hó Garancia / 88% akku
- Telefon felvásárlás!! iPhone 13 Mini/iPhone 13/iPhone 13 Pro/iPhone 13 Pro Max/
- Bomba Ár! Dell XPS 13 9380 - i7-8GEN I 16GB I 512GB SSD I 13,3" FHD I Cam I W11 I Garancia!
- LG 48C2 - 48" OLED EVO - 4K 120Hz 1ms - NVIDIA G-Sync - FreeSync Premium - HDMI 2.1 - A9 Gen5 CPU
- HIBÁTLAN iPhone 13 128GB Midnight -1 ÉV GARANCIA - Kártyafüggetlen, MS3033, 100% Akkumulátor
Állásajánlatok
Cég: FOTC
Város: Budapest