PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
VB Warned me for Coding Methord HELP !!-VBForums
Results 1 to 4 of 4

Thread: VB Warned me for Coding Methord HELP !!

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2009
    Posts
    7

    Unhappy VB Warned me for Coding Methord HELP !!

    IT TAKES CRZY GOD DAMN TIME TO JUST SHOW FORM1 and 2, IT CRASHES IT TOO ! HELP ...........................
    System.InvalidOperationException was unhandled
    Message=Collection was modified; enumeration operation may not execute.
    Source=mscorlib
    StackTrace:
    at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)
    at System.Collections.Generic.List`1.Enumerator.MoveNextRare()
    at System.Collections.Generic.List`1.Enumerator.MoveNext()
    at Microsoft.VisualBasic.PowerPacks.ShapeCollection.Dispose(Boolean disposing)
    at Microsoft.VisualBasic.PowerPacks.ShapeContainer.Dispose(Boolean disposing)
    at System.ComponentModel.Component.Dispose()
    at System.Windows.Forms.Control.Dispose(Boolean disposing)
    at System.Windows.Forms.Form.Dispose(Boolean disposing)
    at WindowsApplication1.Form2.Dispose(Boolean disposing) in C:\Users\Megh\documents\visual studio 2010\Projects\Snippet\Snippet\Form2.Designer.vb:line 13
    at System.ComponentModel.Component.Dispose()
    at System.Windows.Forms.Form.WmClose(Message& m)
    at System.Windows.Forms.Form.WndProc(Message& m)
    at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
    at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
    at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
    at System.Windows.Forms.UnsafeNativeMethods.CallWindowProc(IntPtr wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
    at System.Windows.Forms.NativeWindow.DefWndProc(Message& m)
    at System.Windows.Forms.Form.DefWndProc(Message& m)
    at System.Windows.Forms.Control.WndProc(Message& m)
    at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
    at System.Windows.Forms.ContainerControl.WndProc(Message& m)
    at System.Windows.Forms.Form.WmSysCommand(Message& m)
    at System.Windows.Forms.Form.WndProc(Message& m)
    at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
    at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
    at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
    at System.Windows.Forms.UnsafeNativeMethods.CallWindowProc(IntPtr wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
    at System.Windows.Forms.NativeWindow.DefWndProc(Message& m)
    at System.Windows.Forms.Form.DefWndProc(Message& m)
    at System.Windows.Forms.Control.WndProc(Message& m)
    at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
    at System.Windows.Forms.ContainerControl.WndProc(Message& m)
    at System.Windows.Forms.Form.WmNcButtonDown(Message& m)
    at System.Windows.Forms.Form.WndProc(Message& m)
    at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
    at System.Windows.Forms.Control.ControlNativeWindow.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.IMsoCompo nentManager.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 System.Windows.Forms.Application.Run(ApplicationContext context)
    at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
    at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
    at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
    at WindowsApplication1.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
    at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
    at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
    at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
    at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
    at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
    at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
    at System.Threading.ThreadHelper.ThreadStart()
    InnerException:

    here is my files

    --------------------- form1.vb (startup form) ----------------------

    vb Code:
    1. Public Class Form1
    2.  
    3.     '----------------------------------------------------------------------
    4.     Public Function IsConnectionAvailable() As Boolean        ' Returns True if connection is available
    5.  
    6.         ' check if hotflask.com is avilable
    7.         Dim objUrl As New System.Uri("http://www.google.com/")
    8.         ' Setup WebRequest
    9.         Dim objWebReq As System.Net.WebRequest
    10.         objWebReq = System.Net.WebRequest.Create(objUrl)
    11.         Dim objResp As System.Net.WebResponse
    12.         Try
    13.             ' Attempt to get response and return True
    14.             objResp = objWebReq.GetResponse
    15.             objResp.Close()
    16.             objWebReq = Nothing
    17.             Return True
    18.         Catch ex As Exception
    19.             ' Error, exit and return False
    20.  
    21.             objWebReq = Nothing
    22.             Return False
    23.         End Try
    24.  
    25.     End Function
    26.  
    27.     '----------------------------------------------------------------------
    28.  
    29.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    30.  
    31.         If IsConnectionAvailable() = False Then
    32.             Form2.Show()
    33.             Me.Visible = False
    34.  
    35.         Else
    36.  
    37.             Form2.Show()
    38.             Form2.Visible = False
    39.            
    40.         End If
    41.  
    42.  
    43.     End Sub
    44. End Class

    --------------------- form2.vb -------------------------------
    vb Code:
    1. Public Class Form2
    2.  
    3.     Public Function IsConnectionAvailable() As Boolean        ' Returns True if connection is available
    4.  
    5.         ' check if hotflask.com is avilable
    6.         Dim objUrl As New System.Uri("http://www.google.com/")
    7.         ' Setup WebRequest
    8.         Dim objWebReq As System.Net.WebRequest
    9.         objWebReq = System.Net.WebRequest.Create(objUrl)
    10.         Dim objResp As System.Net.WebResponse
    11.         Try
    12.             ' Attempt to get response and return True
    13.             objResp = objWebReq.GetResponse
    14.             objResp.Close()
    15.             objWebReq = Nothing
    16.             Return True
    17.         Catch ex As Exception
    18.             ' Error, exit and return False
    19.  
    20.             objWebReq = Nothing
    21.             Return False
    22.         End Try
    23.  
    24.     End Function
    25.  
    26.     Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    27.         Me.Size = New Size(516, 216)
    28.  
    29.     End Sub
    30.  
    31.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    32.         If Me.Size = New Size(516, 216) Then
    33.  
    34.             Me.Size = New Size(516, 527)
    35.             Button1.Text = "Hide Information"
    36.  
    37.         ElseIf Me.Size = New Size(516, 527) Then
    38.  
    39.             Me.Size = New Size(516, 216)
    40.             Button1.Text = "Show information"
    41.  
    42.  
    43.  
    44.         End If
    45.  
    46.     End Sub
    47.  
    48.     Private Sub Button1_SizeChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.SizeChanged
    49.  
    50.     End Sub
    51.  
    52.     Private Sub Form2_SizeChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.SizeChanged
    53.             End Sub
    54.  
    55.     Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click
    56.  
    57.     End Sub
    58. End Class


    MY EVENT FILE ___________________________________________

    vb Code:
    1. Imports System.Net
    2.  
    3. Namespace My
    4.  
    5.     Partial Friend Class MyApplication
    6.  
    7.  
    8.         Public Function IsConnectionAvailable() As Boolean        ' Returns True if connection is available
    9.  
    10.             ' Replace [url]www.yoursite.com[/url] with a site that
    11.             ' is guaranteed to be online - perhaps your
    12.             ' corporate site, or microsoft.com
    13.             Dim objUrl As New System.Uri("http://www.google.com/")
    14.             ' Setup WebRequest
    15.             Dim objWebReq As System.Net.WebRequest
    16.             objWebReq = System.Net.WebRequest.Create(objUrl)
    17.             Dim objResp As System.Net.WebResponse
    18.             Try
    19.                 ' Attempt to get response and return True
    20.                 objResp = objWebReq.GetResponse
    21.                 objResp.Close()
    22.                 objWebReq = Nothing
    23.                 Return True
    24.             Catch ex As Exception
    25.                 ' Error, exit and return False
    26.  
    27.                 objWebReq = Nothing
    28.                 Return False
    29.             End Try
    30.  
    31.        End Function
    32.  
    33.         Private Sub MyApplication_NetworkAvailabilityChanged(ByVal sender As Object, ByVal e As Microsoft.VisualBasic.Devices.NetworkAvailableEventArgs) Handles Me.NetworkAvailabilityChanged
    34.             If IsConnectionAvailable() = False Then
    35.  
    36.                 Form2.Visible = True
    37.                 Form1.Visible = False
    38.  
    39.             ElseIf IsConnectionAvailable() = True Then
    40.  
    41.                 Form2.Visible = False
    42.                 Form1.Visible = True
    43.  
    44.             End If
    45.  
    46.         End Sub
    47.  
    48.     End Class
    49.  
    50. End Namespace
    Last edited by smgh; Nov 22nd, 2009 at 02:04 PM.

  2. #2
    ASP.NET Moderator gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,966

    Re: VB Warned me for Coding Methord HELP !!

    Hey,

    Have you tried stepping through your code in the debugger? Which line of code it taking a long time to execute?

    I would suspect that it is this line:

    Code:
    objResp = objWebReq.GetResponse
    But it would be good to confirm.

    Also, can you provide some details as to what exactly you are trying to achieve? Why are you making the request in the first place?

    Gary

  3. #3
    PowerPoster keystone_paul's Avatar
    Join Date
    Nov 2008
    Location
    UK
    Posts
    3,327

    Re: VB Warned me for Coding Methord HELP !!

    I would suspect that it is this line:

    Code:

    objResp = objWebReq.GetResponse

    But it would be good to confirm.
    That line is within a try..catch block that should prevent an unhandled exception I'd have thought.

  4. #4
    ASP.NET Moderator gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,966

    Re: VB Warned me for Coding Methord HELP !!

    Hey,

    You are correct. However, I was referring to the long time of execution that the OP was referring to, not specifically the unhandled exception.

    Gary

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width