Ú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!
- Corsair VENGEANCE SODIMM 2x16GB DDR4 3200MHz CL22 - Új, bontatlan - Eladó!
- iPhone 16 Pro Max 256GB Fekete Titán 96%-os Akksi
- Béreljen minikotró gépet már 24 órától, akár hosszabb időre is
- Bomba Ár! Lenovo ThinkPad E15 Gen2 AMD - Ryzen 5 I 8GB I 256SSD I 15,6" FHD I HDMI I W11 I Gari
- Bomba ár! Lenovo ThinkPad T14s G2 AL - i7-1185G7 I 16GB I 1TSSD I 14" FHD Touch I W11 I Cam I Gari!
- Telefon felvásárlás!! Samsung Galaxy A12/Samsung Galaxy A22/Samsung Galaxy A32/Samsung Galaxy A52
- ÁRGARANCIA!Épített KomPhone i5 14600KF 32/64GB RAM RTX 5070 12GB GAMER PC termékbeszámítással
- BESZÁMÍTÁS! 64GB (2x32) G.Skill Trident Z RGB 4000MHz DDR4 memória garanciával hibátlan működéssel
- HIBÁTLAN iPhone 12 Pro Max 256GB Pacific Blue -1 ÉV GARANCIA - Kártyafüggetlen, MS3371,100% Akkumulá
- Tablet felvásárlás!! Apple iPad, iPad Mini, iPad Air, iPad Pro
Állásajánlatok
Cég: Laptopműhely Bt.
Város: Budapest
Cég: PCMENTOR SZERVIZ KFT.
Város: Budapest