@@ -1955,38 +1955,31 @@ private async void OnActualSizeChanged(object sender, SizeChangedEventArgs e)
19551955 // Initialize RenderClientAdapter when WPF has calculated the actual size of current content.
19561956 CreateOffscreenBrowser ( e . NewSize ) ;
19571957
1958- // If the internal browser isn't initialized then the CEF UI thread is not yet running
1959- // and so we need to set the view rectangle here because it has to be set.
1960- var hasSetViewRect = false ;
1961- if ( ! InternalIsBrowserInitialized ( ) )
1962- {
1963- SetViewRect ( e ) ;
1964- hasSetViewRect = true ;
1965- }
1966-
1967- await CefUiThreadRunAsync ( ( ) =>
1958+ if ( InternalIsBrowserInitialized ( ) )
19681959 {
1969- // If we haven't already set the view rectangle we do it here.
1970- // If the browser is initialized we need to set this on the CEF UI thread to
1971- // avoid the crash issue reported here: https://github.com/cefsharp/CefSharp/issues/2779
1972- if ( ! hasSetViewRect )
1960+ await CefUiThreadRunAsync ( ( ) =>
19731961 {
19741962 SetViewRect ( e ) ;
1975- }
19761963
1977- var host = browser ? . GetHost ( ) ;
1978- if ( host != null && ! host . IsDisposed )
1979- {
1980- try
1981- {
1982- host . WasResized ( ) ;
1983- }
1984- catch ( ObjectDisposedException )
1964+ var host = browser ? . GetHost ( ) ;
1965+ if ( host != null && ! host . IsDisposed )
19851966 {
1986- // See comment in catch in OnWindowStateChanged
1967+ try
1968+ {
1969+ host . WasResized ( ) ;
1970+ }
1971+ catch ( ObjectDisposedException )
1972+ {
1973+ // See comment in catch in OnWindowStateChanged
1974+ }
19871975 }
1988- }
1989- } ) ;
1976+ } ) ;
1977+ }
1978+ else
1979+ {
1980+ //If the browser hasn't been created yet then directly update the viewRect
1981+ SetViewRect ( e ) ;
1982+ }
19901983 }
19911984
19921985 private void SetViewRect ( SizeChangedEventArgs e )
@@ -2039,16 +2032,13 @@ await CefUiThreadRunAsync(async () =>
20392032 //browsers of the same origin will share the same zoomlevel and
20402033 //we need to track the update, so our ZoomLevelProperty works
20412034 //properly
2042- await browser . GetHost ( ) . GetZoomLevelAsync ( ) . ContinueWith ( t =>
2035+ var zoomLevel = await browser . GetHost ( ) . GetZoomLevelAsync ( ) ;
2036+
2037+ if ( ! IsDisposed )
20432038 {
2044- if ( ! IsDisposed )
2045- {
2046- SetCurrentValue ( ZoomLevelProperty , t . Result ) ;
2047- }
2048- } ,
2049- CancellationToken . None ,
2050- TaskContinuationOptions . OnlyOnRanToCompletion ,
2051- TaskScheduler . FromCurrentSynchronizationContext ( ) ) ;
2039+ SetCurrentValue ( ZoomLevelProperty , zoomLevel ) ;
2040+ }
2041+
20522042 }
20532043 }
20542044 }
0 commit comments