I want to use vtk for registration visualization

#include<vtkSmartPointer.h>
#include<vtkDataObject.h>
#include<vtkImageFlip.h>
#include<vtkImageViewer2.h>
#include<vtkRenderWindow.h>
#include <vtkAutoInit.h>
#include<vtkImageData.h>
#include<vtkImageMapper.h>
#include<vtkImageActor.h>
#include<vtkRenderer.h>
#include<vtkRenderWindowInteractor.h>
#include<string>
#include <thread>
#include<Windows.h>
#include<functional>
VTK_MODULE_INIT(vtkRenderingOpenGL2);
VTK_MODULE_INIT(vtkInteractionStyle);
VTK_MODULE_INIT(vtkRenderingFreeType);
class VisualRegistration
{
public:
	VisualRegistration()
	{
		actor =vtkSmartPointer<vtkImageActor>::New();
		render =vtkSmartPointer<vtkRenderer>::New();
		window =vtkSmartPointer<vtkRenderWindow>::New();
	}
	~VisualRegistration();
	int i = 0;

	void Updata(vtkImageFlip* image) {
	
	
		actor->SetInputData(image->GetOutput());
		render->AddActor(actor);
		render->ResetCamera();
		render->SetBackground(1, 1, 1);
		window->AddRenderer(render);
		window->SetSize(640, 480);
		window->SetWindowName("ImageViewer3D");
		window->Render();

	}

private:
	vtkSmartPointer<vtkImageActor> actor;
	vtkSmartPointer<vtkRenderer> render;
	vtkSmartPointer<vtkRenderWindow> window;
};

This is my code. I call Updata to update the image and render the window, but the window will not respond randomly, which happens very frequently. Updata is called in the optimizer IterationEvent in the registration.