• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

VB.NET InvalidOperationException类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了VB.NET中System.InvalidOperationException的典型用法代码示例。如果您正苦于以下问题:VB.NET InvalidOperationException类的具体用法?VB.NET InvalidOperationException怎么用?VB.NET InvalidOperationException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了InvalidOperationException类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的VB.NET代码示例。

示例1: DoSomeWork

Private Async Sub threadExampleBtn_Click(sender As Object, e As RoutedEventArgs) Handles threadExampleBtn.Click
    textBox1.Text = String.Empty

    textBox1.Text = "Simulating work on UI thread." + vbCrLf
    DoSomeWork(20)
    textBox1.Text += "Work completed..." + vbCrLf

    textBox1.Text += "Simulating work on non-UI thread." + vbCrLf
    Await Task.Factory.StartNew(Sub()
                                    DoSomeWork(1000)
                                End Sub)
    textBox1.Text += "Work completed..." + vbCrLf
End Sub

Private Async Sub DoSomeWork(milliseconds As Integer)
    ' Simulate work.
    Await Task.Delay(milliseconds)

    ' Report completion.
    Dim msg = String.Format("Some work completed in {0} ms.", milliseconds) + vbCrLf
    textBox1.Text += msg
End Sub
开发者ID:VB.NET开发者,项目名称:System,代码行数:22,代码来源:InvalidOperationException


示例2: DoSomeWork

Private Async Sub DoSomeWork(milliseconds As Integer)
    ' Simulate work.
    Await Task.Delay(milliseconds)

    ' Report completion.
    Dim uiAccess As Boolean = textBox1.Dispatcher.CheckAccess()
    Dim msg As String = String.Format("Some work completed in {0} ms. on {1}UI thread",
                                      milliseconds, If(uiAccess, String.Empty, "non-")) + 
                                      vbCrLf 
    If uiAccess Then
        textBox1.Text += msg
    Else
        textBox1.Dispatcher.Invoke( Sub() textBox1.Text += msg)
    End If
End Sub
开发者ID:VB.NET开发者,项目名称:System,代码行数:15,代码来源:InvalidOperationException


示例3: DoSomeWork

Private Async Sub DoSomeWork(milliseconds As Integer)
    ' Simulate work.
    Await Task.Delay(milliseconds)

    ' Report completion.
    Dim uiAccess As Boolean = textBox1.Dispatcher.HasThreadAccess
    Dim msg As String = String.Format("Some work completed in {0} ms. on {1}UI thread" + vbCrLf,
                                      milliseconds, If(uiAccess, String.Empty, "non-"))
    If (uiAccess) Then
        textBox1.Text += msg
    Else
        Await textBox1.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, Sub() textBox1.Text += msg)
    End If
End Sub
开发者ID:VB.NET开发者,项目名称:System,代码行数:14,代码来源:InvalidOperationException


示例4: DoSomeWork

Dim lines As New List(Of String)()
Private Async Sub threadExampleBtn_Click(sender As Object, e As EventArgs) Handles threadExampleBtn.Click
    textBox1.Text = String.Empty
    lines.Clear()

    lines.Add("Simulating work on UI thread.")
    textBox1.Lines = lines.ToArray()
    DoSomeWork(20)

    lines.Add("Simulating work on non-UI thread.")
    textBox1.Lines = lines.ToArray()
    Await Task.Run(Sub() DoSomeWork(1000))

    lines.Add("ThreadsExampleBtn_Click completes. ")
    textBox1.Lines = lines.ToArray()
End Sub

Private Async Sub DoSomeWork(milliseconds As Integer)
    ' Simulate work.
    Await Task.Delay(milliseconds)

    ' Report completion.
    lines.Add(String.Format("Some work completed in {0} ms on UI thread.", milliseconds))
    textBox1.Lines = lines.ToArray()
End Sub
开发者ID:VB.NET开发者,项目名称:System,代码行数:25,代码来源:InvalidOperationException


示例5: DoSomeWork

Private Async Sub DoSomeWork(milliseconds As Integer)
    ' Simulate work.
    Await Task.Delay(milliseconds)

    ' Report completion.
    Dim uiMarshal As Boolean = textBox1.InvokeRequired
    Dim msg As String = String.Format("Some work completed in {0} ms. on {1}UI thread" + vbCrLf,
                                      milliseconds, If(uiMarshal, String.Empty, "non-"))
    lines.Add(msg)

    If uiMarshal Then
        textBox1.Invoke(New Action(Sub() textBox1.Lines = lines.ToArray()))
    Else
        textBox1.Lines = lines.ToArray()
    End If
End Sub
开发者ID:VB.NET开发者,项目名称:System,代码行数:16,代码来源:InvalidOperationException


示例6: Main

' 导入命名空间
Imports System.Collections.Generic

Module Example
   Public Sub Main()
      Dim numbers As New List(Of Integer)( { 1, 2, 3, 4, 5 } )
      For Each number In numbers
         Dim square As Integer = CInt(Math.Pow(number, 2))
         Console.WriteLine("{0}^{1}", number, square)
         Console.WriteLine("Adding {0} to the collection..." + vbCrLf, 
                           square)
         numbers.Add(square)
      Next
   End Sub
End Module
开发者ID:VB.NET开发者,项目名称:System,代码行数:15,代码来源:InvalidOperationException

输出:

1^1
Adding 1 to the collection...


Unhandled Exception: System.InvalidOperationException: Collection was modified; 
enumeration operation may not execute.
at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)
at System.Collections.Generic.List`1.Enumerator.MoveNextRare()
at Example.Main()


示例7: Main

' 导入命名空间
Imports System.Collections.Generic

Module Example
   Public Sub Main()
      Dim numbers As New List(Of Integer)( { 1, 2, 3, 4, 5 } )
      Dim upperBound = numbers.Count - 1

      For ctr As Integer = 0 To upperBound
         Dim square As Integer = CInt(Math.Pow(numbers(ctr), 2))
         Console.WriteLine("{0}^{1}", numbers(ctr), square)
         Console.WriteLine("Adding {0} to the collection..." + vbCrLf, 
                           square)
         numbers.Add(square)
      Next
   
      Console.WriteLine("Elements now in the collection: ")
      For Each number In numbers
         Console.Write("{0}    ", number)
      Next   
   End Sub
End Module
开发者ID:VB.NET开发者,项目名称:System,代码行数:22,代码来源:InvalidOperationException

输出:

1^1
Adding 1 to the collection...

2^4
Adding 4 to the collection...

3^9
Adding 9 to the collection...

4^16
Adding 16 to the collection...

5^25
Adding 25 to the collection...

Elements now in the collection:
1    2    3    4    5    1    4    9    16    25


示例8: Main

' 导入命名空间
Imports System.Collections.Generic

Module Example
   Public Sub Main()
      Dim numbers As New List(Of Integer)( { 1, 2, 3, 4, 5 } )
      Dim temp As New List(Of Integer)()
      
      ' Square each number and store it in a temporary collection.
      For Each number In numbers
         Dim square As Integer = CInt(Math.Pow(number, 2))
         temp.Add(square)
      Next
    
      ' Combine the numbers into a single array.
      Dim combined(numbers.Count + temp.Count - 1) As Integer 
      Array.Copy(numbers.ToArray(), 0, combined, 0, numbers.Count)
      Array.Copy(temp.ToArray(), 0, combined, numbers.Count, temp.Count)
      
      ' Iterate the array.
      For Each value In combined
         Console.Write("{0}    ", value)
      Next
   End Sub
End Module
开发者ID:VB.NET开发者,项目名称:System,代码行数:25,代码来源:InvalidOperationException

输出:

1    2    3    4    5    1    4    9    16    25


示例9: New

' 导入命名空间
Imports System.Collections.Generic

Public Class Person
   Public Sub New(fName As String, lName As String)
      FirstName = fName
      LastName = lName
   End Sub
   
   Public Property FirstName As String
   Public Property LastName As String
End Class

Module Example
   Public Sub Main()
      Dim people As New List(Of Person)()
      
      people.Add(New Person("John", "Doe"))
      people.Add(New Person("Jane", "Doe"))
      people.Sort()
      For Each person In people
         Console.WriteLine("{0} {1}", person.FirstName, person.LastName)
      Next
   End Sub
End Module
开发者ID:VB.NET开发者,项目名称:System,代码行数:25,代码来源:InvalidOperationException

输出:

Unhandled Exception: System.InvalidOperationException: Failed to compare two elements in the array. ---> 
System.ArgumentException: At least one object must implement IComparable.
at System.Collections.Comparer.Compare(Object a, Object b)
at System.Collections.Generic.ArraySortHelper`1.SwapIfGreater(T[] keys, IComparer`1 comparer, Int32 a, Int32 b)
at System.Collections.Generic.ArraySortHelper`1.DepthLimitedQuickSort(T[] keys, Int32 left, Int32 right, IComparer`1 comparer, Int32 depthLimit)
at System.Collections.Generic.ArraySortHelper`1.Sort(T[] keys, Int32 index, Int32 length, IComparer`1 comparer)
--- End of inner exception stack trace ---
at System.Collections.Generic.ArraySortHelper`1.Sort(T[] keys, Int32 index, Int32 length, IComparer`1 comparer)
at System.Array.Sort[T](T[] array, Int32 index, Int32 length, IComparer`1 comparer)
at System.Collections.Generic.List`1.Sort(Int32 index, Int32 count, IComparer`1 comparer)
at Example.Main()


示例10: New

' 导入命名空间
Imports System.Collections.Generic

Public Class Person : Implements IComparable(Of Person)
   Public Sub New(fName As String, lName As String)
      FirstName = fName
      LastName = lName
   End Sub
   
   Public Property FirstName As String
   Public Property LastName As String
   
   Public Function CompareTo(other As Person) As Integer _
          Implements IComparable(Of Person).CompareTo
      Return String.Format("{0} {1}", LastName, FirstName).
             CompareTo(String.Format("{0} {1}", LastName, FirstName))    
   End Function       
End Class

Module Example
   Public Sub Main()
      Dim people As New List(Of Person)()
      
      people.Add(New Person("John", "Doe"))
      people.Add(New Person("Jane", "Doe"))
      people.Sort()
      For Each person In people
         Console.WriteLine("{0} {1}", person.FirstName, person.LastName)
      Next
   End Sub
End Module
开发者ID:VB.NET开发者,项目名称:System,代码行数:31,代码来源:InvalidOperationException

输出:

Jane Doe
John Doe


示例11: New

' 导入命名空间
Imports System.Collections.Generic

Public Class Person
   Public Sub New(fName As String, lName As String)
      FirstName = fName
      LastName = lName
   End Sub
   
   Public Property FirstName As String
   Public Property LastName As String
End Class

Public Class PersonComparer : Implements IComparer(Of Person)
   Public Function Compare(x As Person, y As Person) As Integer _
          Implements IComparer(Of Person).Compare
      Return String.Format("{0} {1}", x.LastName, x.FirstName).
             CompareTo(String.Format("{0} {1}", y.LastName, y.FirstName))    
   End Function       
End Class

Module Example
   Public Sub Main()
      Dim people As New List(Of Person)()
      
      people.Add(New Person("John", "Doe"))
      people.Add(New Person("Jane", "Doe"))
      people.Sort(New PersonComparer())
      For Each person In people
         Console.WriteLine("{0} {1}", person.FirstName, person.LastName)
      Next
   End Sub
End Module
开发者ID:VB.NET开发者,项目名称:System,代码行数:33,代码来源:InvalidOperationException

输出:

Jane Doe
John Doe


示例12: New

' 导入命名空间
Imports System.Collections.Generic

Public Class Person
   Public Sub New(fName As String, lName As String)
      FirstName = fName
      LastName = lName
   End Sub
   
   Public Property FirstName As String
   Public Property LastName As String
End Class

Module Example
   Public Sub Main()
      Dim people As New List(Of Person)()
      
      people.Add(New Person("John", "Doe"))
      people.Add(New Person("Jane", "Doe"))
      people.Sort(AddressOf PersonComparison)
      For Each person In people
         Console.WriteLine("{0} {1}", person.FirstName, person.LastName)
      Next
   End Sub
   
   Public Function PersonComparison(x As Person, y As Person) As Integer
      Return String.Format("{0} {1}", x.LastName, x.FirstName).
             CompareTo(String.Format("{0} {1}", y.LastName, y.FirstName))    
   End Function
End Module
开发者ID:VB.NET开发者,项目名称:System,代码行数:30,代码来源:InvalidOperationException

输出:

Jane Doe
John Doe


示例13: Example

' 导入命名空间
Imports System.Linq

Module Example
   Public Sub Main()
      Dim queryResult = New Integer?() { 1, 2, Nothing, 4 }
      Dim map = queryResult.Select(Function(nullableInt) CInt(nullableInt))
      
      ' Display list.
      For Each num In map
         Console.Write("{0} ", num)
      Next
      Console.WriteLine()   
   End Sub
End Module
' The example displays thIe following output:
'    1 2
'    Unhandled Exception: System.InvalidOperationException: Nullable object must have a value.
'       at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)
'       at Example.<Main>b__0(Nullable`1 nullableInt)
'       at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
'       at Example.Main()
开发者ID:VB.NET开发者,项目名称:System,代码行数:22,代码来源:InvalidOperationException


示例14: Main

' 导入命名空间
Imports System.Linq

Module Example
   Public Sub Main()
      Dim queryResult = New Integer?() { 1, 2, Nothing, 4 }
      Dim numbers = queryResult.Select(Function(nullableInt) _ 
                                          CInt(nullableInt.GetValueOrDefault()))
      ' Display list.
      For Each number In numbers
         Console.Write("{0} ", number)
      Next
      Console.WriteLine()
      
      ' Use -1 to indicate a missing values.
      numbers = queryResult.Select(Function(nullableInt) _   
                                      CInt(If(nullableInt.HasValue, nullableInt, -1)))
      ' Display list.
      For Each number In numbers
         Console.Write("{0} ", number)
      Next
      Console.WriteLine()
                                      
   End Sub
End Module
开发者ID:VB.NET开发者,项目名称:System,代码行数:25,代码来源:InvalidOperationException

输出:

1 2 0 4
1 2 -1 4


示例15: Main

' 导入命名空间
Imports System.Linq

Module Example
   Public Sub Main()
      Dim data() As Integer = { 1, 2, 3, 4 }
      Dim average = data.Where(Function(num) num > 4).Average()
      Console.Write("The average of numbers greater than 4 is {0}",
                    average)
   End Sub
End Module
开发者ID:VB.NET开发者,项目名称:System,代码行数:11,代码来源:InvalidOperationException

输出:

Unhandled Exception: System.InvalidOperationException: Sequence contains no elements
at System.Linq.Enumerable.Average(IEnumerable`1 source)
at Example.Main()


示例16: Main

' 导入命名空间
Imports System.Linq

Module Example
   Public Sub Main()
       Dim dbQueryResults() As Integer = { 1, 2, 3, 4 }
       Dim moreThan4 = dbQueryResults.Where(Function(num) num > 4)
   
       If moreThan4.Any() Then
           Console.WriteLine("Average value of numbers greater than 4: {0}:", 
                             moreThan4.Average())
       Else
           ' Handle empty collection. 
           Console.WriteLine("The dataset has no values greater than 4.")
       End If    
   End Sub
End Module
开发者ID:VB.NET开发者,项目名称:System,代码行数:17,代码来源:InvalidOperationException

输出:

The dataset has no values greater than 4.


示例17: Main

' 导入命名空间
Imports System.Linq

Module Example
   Public Sub Main()
      Dim dbQueryResults() As Integer = { 1, 2, 3, 4 }

      Dim firstNum = dbQueryResults.First(Function(n) n > 4)

      Console.WriteLine("The first value greater than 4 is {0}", 
                        firstNum)
   End Sub
End Module
开发者ID:VB.NET开发者,项目名称:System,代码行数:13,代码来源:InvalidOperationException

输出:

Unhandled Exception: System.InvalidOperationException: 
Sequence contains no matching element
at System.Linq.Enumerable.First[TSource](IEnumerable`1 source, Func`2 predicate)
at Example.Main()


示例18: Main

' 导入命名空间
Imports System.Linq

Module Example
   Public Sub Main()
      Dim dbQueryResults() As Integer = { 1, 2, 3, 4 }

      Dim firstNum = dbQueryResults.FirstOrDefault(Function(n) n > 4)

      If firstNum = 0 Then
         Console.WriteLIne("No value is greater than 4.")
      Else   
         Console.WriteLine("The first value greater than 4 is {0}", 
                           firstNum)
      End If                     
   End Sub
End Module
开发者ID:VB.NET开发者,项目名称:System,代码行数:17,代码来源:InvalidOperationException

输出:

No value is greater than 4.


示例19: Main

' 导入命名空间
Imports System.Linq

Module Example
   Public Sub Main()
       Dim dbQueryResults() As Integer = { 1, 2, 3, 4 }
   
       Dim singleObject = dbQueryResults.Single(Function(value) value > 4)
   
       ' Display results.
       Console.WriteLine("{0} is the only value greater than 4", 
                         singleObject)
   End Sub
End Module
开发者ID:VB.NET开发者,项目名称:System,代码行数:14,代码来源:InvalidOperationException

输出:

Unhandled Exception: System.InvalidOperationException: 
Sequence contains no matching element
at System.Linq.Enumerable.Single[TSource](IEnumerable`1 source, Func`2 predicate)
at Example.Main()


示例20: Main

' 导入命名空间
Imports System.Linq

Module Example
   Public Sub Main()
       Dim dbQueryResults() As Integer = { 1, 2, 3, 4 }
   
       Dim singleObject = dbQueryResults.SingleOrDefault(Function(value) value > 2)
   
       If singleObject <> 0 Then
           Console.WriteLine("{0} is the only value greater than 2", 
                             singleObject)
       Else
           ' Handle an empty collection.
           Console.WriteLine("No value is greater than 2")
       End If    
   End Sub
End Module
开发者ID:VB.NET开发者,项目名称:System,代码行数:18,代码来源:InvalidOperationException

输出:

Unhandled Exception: System.InvalidOperationException: 
Sequence contains more than one matching element
at System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable`1 source, Func`2 predicate)
at Example.Main()



注:本文中的System.InvalidOperationException类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
VB.NET GZipStream类代码示例发布时间:2022-05-24
下一篇:
VB.NET SortVersion类代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap