Hi,@shy akocat.
I reproduced your problem, the code reported an error under .NET Framework4.8, but it worked fine under .NET 7. (Windows 10 22H2)
It Seems that your code is rigging the creation of a Direct3D object and a Device object, which might be affecting the underlying graphics context and causing a conflict with the DispatcherTimer.
Here's a workaround to accomplish the same thing in .NET Framework. If you'd like to use the original code, you can file it on Developer Community.
You could try wrapping your DevilCode()
function call within a separate thread to ensure it doesn't interfere with the UI and the DispatcherTimer.
public MainWindow()
{
InitializeComponent();
Loaded += MainWindow_Loaded; // Subscribe to the Loaded event
}
private void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
// Call DevilCode function in a separate thread
Task.Run(() => DevilCode());
}
public void DevilCode()
{
var d3d = new Direct3D();
var device = new Device(
d3d,
0,
DeviceType.Hardware,
IntPtr.Zero,
CreateFlags.HardwareVertexProcessing | CreateFlags.Multithreaded,
new PresentParameters(100, 100, Format.A8R8G8B8, 2, MultisampleType.None, 0, SwapEffect.Discard, IntPtr.Zero, windowed: true, enableAutoDepthStencil: true, Format.D24X8, PresentFlags.None, 0, PresentInterval.Immediate));
}
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.