[WPF] Application_Startup vs OnStartup

WPF์—์„œ App.xaml.cs ์—์„œ MainWindow ์ฐฝ์ด ๋œจ๊ธฐ ์ „์— ๋ญ”๊ฐ€ ํ•˜๊ณ  ์‹ถ๋‹ค๋ฉด Application_Startup ๋˜๋Š” OnStartUp์„ overrideํ•ด์„œ ์‚ฌ์šฉํ•˜๋Š” ๋“ฏํ•œ๋ฐ, ๋‘ ๊ฐ€์ง€์˜ ์ฐจ์ด์ ์ด ๋ฌด์—‡์ธ๊ฐ€์š”?

์ข‹์•„์š” 2

@Vincent Application ๋‚ด๋ถ€์—์„œ virtual OnStartup ๋ฉ”์„œ๋“œ๊ฐ€ ์ƒ์„ฑ์ž ๋ถ€๋ถ„์—์„œ ์‹คํ–‰๋˜๊ฑฐ๋“ ์š”.

public Application()
{
    OnStartup(e);
}

virtual OnStartup(event e)
{
    Startup.Invoke(e);
}

(์†Œ์Šค๋Š” ์ •ํ™•ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹คโ€ฆ ๋Œ€๋žต ์ด๋Ÿฐ์‹์ผ๊ฑฐ๋ผ๋Š”โ€ฆ)

๊ทธ๋ž˜์„œ OnStartup์ด ๋จผ์ € ์‹คํ–‰๋˜๊ณ ,
Startup ์ด๋ฒคํŠธ๊ฐ€ ํ˜ธ์ถœ๋ฉ๋‹ˆ๋‹ค.

๊ทธ๋ž˜์„œ ๋งŒ์•ฝ์— base.OnStartup(e); ๋ถ€๋ถ„์„ ์ง€์šฐ๊ฒŒ ๋˜๋ฉด Startup ์ด๋ฒคํŠธ๋„ ํ˜ธ์ถœ๋˜์ง€ ์•Š์•„์š”~

public class App : Application
{
    public App()
    {
        this.Startup += App_Startup;
    }
    
    void App_Startup(sender, e)
    {

    }

    public override OnStartup(e)
    {
        // base.OnStartup(e); ๋งŒ์•ฝ ์ง€์šฐ๋ฉด Startup ์ด๋ฒคํŠธ๋„ ํ˜ธ์ถœ x
    }
}
์ข‹์•„์š” 3

์™€โ€ฆ๋”ฑ ์ œ๊ฐ€ ์›ํ•˜๋˜ ๋‹ต๋ณ€์ž…๋‹ˆ๋‹ค. base.OnStartup ์–ด๋–ป๊ฒŒ๋˜๋Š”์ง€๋„ ์—ฌ์ญค๋ณด๋ ค๊ณ  ํ–ˆ๋Š”๋ฐโ€ฆใ…‹ใ…‹ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค!

์ข‹์•„์š” 1

์ด์ œ ์šฐ๋ฆฌ๋Š” WPF์˜ ์†Œ์Šค์ฝ”๋“œ๋ฅผ ์‚ดํŽด๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค :open_mouth:

wpf/Application.cs at main ยท dotnet/wpf (github.com)

์ƒ์„ฑ์ž์—์„œ OnStartup()์„ ํ˜ธ์ถœํ•˜๋Š” 160๋ฒˆ์งธ ์ค„,
OnStartup()์—์„œ Startup ์ด๋ฒคํŠธ๊ฐ€ ์žˆ์„ ๊ฒฝ์šฐ ํ˜ธ์ถœํ•ด์ฃผ๋Š” 1216๋ฒˆ์งธ ์ค„์„ ์‚ดํŽด๋ณด์‹œ๋ฉด,

@james.lee ๋‹˜์˜ ๋‹ต๋ณ€๊ณผ ์œ ์‚ฌํ•จ์„ ์•Œ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค!

์ข‹์•„์š” 4