首页 > 其他分享 >WPF initialization for opening and unitialization for closing process

WPF initialization for opening and unitialization for closing process

时间:2024-03-23 22:56:07浏览次数:20  
标签:unitialization opening process LogMsg System DebugWriteLineInfo Window func usin

//xaml
<Window x:Class="WpfApp10.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WpfApp10"
        mc:Ignorable="d" Initialized="Window_Initialized" Activated="Window_Activated"
        Loaded="Window_Loaded" ContentRendered="Window_ContentRendered" 
        Deactivated="Window_Deactivated" Closing="Window_Closing" Unloaded="Window_Unloaded"
        Closed="Window_Closed" WindowState="Maximized"
        Title="MainWindow" Height="450" Width="800">
    <Grid>
        
    </Grid>
</Window>


//xaml.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Runtime.CompilerServices;
using System.IO;

namespace WpfApp10
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            LogMsg(DebugWriteLineInfo());
            InitializeComponent(); 
        }

        private void Window_Initialized(object sender, EventArgs e)
        {
            LogMsg(DebugWriteLineInfo());
        }

        private void Window_Activated(object sender, EventArgs e)
        {
            LogMsg(DebugWriteLineInfo());
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            LogMsg(DebugWriteLineInfo());
        }

        private void Window_ContentRendered(object sender, EventArgs e)
        {
            LogMsg(DebugWriteLineInfo());
        }

        private void Window_Deactivated(object sender, EventArgs e)
        {
            LogMsg(DebugWriteLineInfo());
        }

        private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            LogMsg(DebugWriteLineInfo());
        }

        private void Window_Unloaded(object sender, RoutedEventArgs e)
        {
            LogMsg(DebugWriteLineInfo());
        }

        private void Window_Closed(object sender, EventArgs e)
        {
            LogMsg(DebugWriteLineInfo());
        }

        private string DebugWriteLineInfo([CallerLineNumber] int lineNum = 0, [CallerMemberName] string func=null,
            [CallerFilePath] string file=null)
        {
            return $"lineNum{lineNum},func:{func}";
        }

        private void LogMsg(string msg)
        {
            using (StreamWriter writer = new StreamWriter("WpfInitializeSequence.txt", true, Encoding.UTF8))
            {
                writer.WriteLine(msg+"\n");
            }
        }
    }
}

 

 

Open and close the generated window to validate the sequence/order

lineNum27,func:.ctor

lineNum33,func:Window_Initialized

lineNum38,func:Window_Activated

lineNum43,func:Window_Loaded

lineNum48,func:Window_ContentRendered

lineNum58,func:Window_Closing

lineNum53,func:Window_Deactivated

lineNum68,func:Window_Closed

 

As the  executed result shows,the sequence of opening window  is constructor,Initialized,Activated,Loaded,ContentRendered.

And closing window the sequence is Closing,Deactivated,Closed.

 

标签:unitialization,opening,process,LogMsg,System,DebugWriteLineInfo,Window,func,usin
From: https://www.cnblogs.com/Fred1987/p/18091847

相关文章

  • 五、Spring源码学习之postProcessBeanFactory方法
    简介在应用程序上下文完成其标准初始化后,修改其内部的BeanFactory。此时,所有的bean定义都已经加载完成,但还没有任何bean被实例化。这允许在某些ApplicationContext实现中注册特殊的BeanPostProcessor等。在应用程序上下文的初始化过程中,会经历多个阶段。其中,一个关键阶段......
  • C++ Qt开发:QProcess进程管理模块
    Qt是一个跨平台C++图形界面开发库,利用Qt可以快速开发跨平台窗体应用程序,在Qt中我们可以通过拖拽的方式将不同组件放到指定的位置,实现图形化开发极大的方便了开发效率,本章将重点介绍如何运用QProcess组件实现针对进程的控制管理等。当你在使用Qt进行跨平台应用程序开发时,经常需要......
  • 操作系统综合题之“采用记录型信号量机制实现进程INPUT、PROCESS和OUTPUT的同步算法(
    1.问题:系统中有有三个进程INPUT、PROCESS和OUTPUT,共用两个缓冲区BUF1和BUF2。假期设BUF1中最多可放10个数据,现已放入了2个数据;BUF2最多可放5个数据。INPUT进程负责不断将输入的原始数据推送入BUF1,PROCESS进程负责从BUF1中取出原始数据进行处理,并将处理后的结果数据送入到BUF2中,OUT......
  • Cannot connect to already running IDE instance. Exception: Process 6,367 is stil
    当IntelliJIDEA显示“CannotconnecttoalreadyrunningIDEinstance.Exception:Process6,367isstillrunning”这个错误消息时,意味着它试图连接到一个已经在运行中的实例,但因为某些原因,这个操作失败了。这通常发生在IDEA无法正常关闭或在后台无法正确管理其进程......
  • 僵尸进程_ZombieProcess
            僵尸进程(ZombieProcess)在计算机操作系统中,特别是类Unix系统中,是指一种特殊的进程状态。当一个子进程已经完成了其生命周期并通过`exit()`系统调用正常退出或者异常终止时,它并不会立即从系统进程中消失。此时,虽然它的所有资源(如内存、打开的文件描述符等)都已经......
  • MySQL 术语 : processes, threads, connections
    MySQL是单进程、多线程架构。通常说的连接(connections)是指TCP/IP连接。每个连接对应一个专用的线程。但是这些线程有时候被叫做进程,有时候被当作连接。这也是为什么processes,threads,connections三者会让人产生混淆的原因。MySQL确实是一个单进程服务器。它是多线程的,因为......
  • InstantiationAwareBeanPostProcessor 接口实现
    BeanPostProcessor结构图1code如下:packagecom.gientech.resolveBeforeInstantiation;publicclassBeforeInstantiation{publicvoiddoSomething(){System.out.println("dosomething......");}}packagecom.gientech.resolveBefor......
  • Coursera自然语言处理专项课程01:Natural Language Processing with Classification an
    NaturalLanguageProcessingwithClassificationandVectorSpacesCourseCertificate本文是NaturalLanguageProcessingwithClassificationandVectorSpaces这门课的学习笔记,仅供个人学习使用,如有侵权,请联系删除。文章目录NaturalLanguageProcessingwi......
  • 【WEEK2】 【DAY5】Data Processing and Redirection - Data Processing【English Ver
    2024.3.8FridayFollowingthepreviousarticle【WEEK2】【DAY4】DataProcessingandRedirection-MethodsofResultRedirection【EnglishVersion】Contents5.2.DataProcessing5.2.1.SubmittingProcessedData5.2.1.1.Thesubmittedfieldnamematches......
  • Prometheus监控系统进程---process-exporter
    参考文档Namedprocessesstacked|GrafanaLabsNamedprocesses|GrafanaLabsncabatoff/process-exporter:Prometheus导出器,用于挖掘/proc以报告所选进程(github.com)操作步骤下载安装包wgethttps://github.com/ncabatoff/process-exporter/releases/download/v0.7.......