I get hit with this System.OutOfMemoryException every time I try the project.
This was supposed to change the picture box to different pictures (ads). I tried changing the picture formats, they were .png files and now .jpg files.
Here is the code:
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Dim gen As Random = New Random()
Dim choice As Integer = gen.Next(0, 4)
If choice = 0 Then
PictureBox1.Image = Image.FromFile("Screenshot 2023-03-25 102759.jpg")
ElseIf choice = 1 Then
PictureBox1.Image = Image.FromFile("ad2.jpg")
ElseIf choice = 2 Then
PictureBox1.Image = Image.FromFile("ad4.jpg")
Else
PictureBox1.Image = Image.FromFile("ad5.jpg")
End If
End Sub
and here is the stack trace:
StackTrace
at System.Drawing.Image.FromFile(String filename, Boolean useEmbeddedColorManagement)
at System.Drawing.Image.FromFile(String filename)
at Word_game_prototype.Form1.Timer1_Tick(Object sender, EventArgs e) in C:\Visual studio (delete this junk)\Word game prototype\Word game prototype\Form1.vb:line 20
at System.Windows.Forms.Timer.OnTick(EventArgs e)
at System.Windows.Forms.Timer.TimerNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
at Word_game_prototype.My.MyApplication.Main(String[] Args) in :line 83