handle window operation in main thread