{"id":5991,"date":"2018-11-08T15:10:19","date_gmt":"2018-11-08T06:10:19","guid":{"rendered":"https:\/\/elleneast.com\/?p=5991"},"modified":"2018-12-12T21:35:26","modified_gmt":"2018-12-12T12:35:26","slug":"%e3%80%90vb-net%e3%80%91%e9%9d%9e%e5%90%8c%e6%9c%9f%e3%81%ae%e3%83%97%e3%83%ad%e3%82%b0%e3%83%ac%e3%82%b9%e3%83%90%e3%83%bc%e3%82%92%e4%bd%9c%e6%88%90%e3%81%99%e3%82%8b","status":"publish","type":"post","link":"https:\/\/elleneast.com\/?p=5991","title":{"rendered":"\u3010VB.NET\u3011\u975e\u540c\u671f\u306e\u30d7\u30ed\u30b0\u30ec\u30b9\u30d0\u30fc\u3092\u4f5c\u6210\u3059\u308b"},"content":{"rendered":"<p>VB.NET \u3067\u30d7\u30ed\u30b0\u30ec\u30b9\u30d0\u30fc\u3092\u975e\u540c\u671f\u3067\u52d5\u4f5c\u3055\u305b\u3066\u307f\u307e\u3059\u3002<\/p>\n<p>VB.NET \u306b\u304a\u3051\u308b\u975e\u540c\u671f\u51e6\u7406\u3001\u30ad\u30e3\u30f3\u30bb\u30eb\u51e6\u7406\u3001Progress \u30af\u30e9\u30b9\u306e\u4f7f\u3044\u65b9\u7b49\u306e\u30b5\u30f3\u30d7\u30eb\u306b\u306a\u3063\u3066\u307e\u3059\u3002C# \u306e\u60c5\u5831\u306f\u305f\u304f\u3055\u3093\u898b\u3064\u304b\u308b\u3051\u3069\u3001VB.NET \u306e\u30b5\u30f3\u30d7\u30eb\u306f\u5c11\u306a\u304f\u3066\u82e6\u52b4\u3057\u307e\u3059\u306d\u3002<\/p>\n<p>\u3053\u306e\u8a18\u4e8b\u3067\u306f\u30c0\u30a4\u30a2\u30ed\u30b0\u3092 WPF \u3067\u4f5c\u3063\u3066\u307e\u3059\u304c\u3001 Forms \u3067\u4f5c\u3063\u305f\u3068\u3057\u3066\u3082\u3001\u30d7\u30ed\u30b0\u30e9\u30e0\u30b3\u30fc\u30c9\u306f\u5171\u901a\u3067\u4f7f\u3048\u308b\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p>\u4e0b\u306e\u30d3\u30c7\u30aa\u3067\u306f\u3001\u30d7\u30ed\u30b0\u30ec\u30b9\u30d0\u30fc\u304c\u975e\u540c\u671f\u3067\u52d5\u3044\u3066\u3044\u308b\u3053\u3068\u3092\u793a\u3059\u305f\u3081\u306b\u3001\u30d7\u30ed\u30b0\u30ec\u30b9\u30d0\u30fc\u306e\u52d5\u4f5c\u4e2d\u306b\u30c0\u30a4\u30a2\u30ed\u30b0\u3092\u52d5\u304b\u3057\u305f\u308a\u30b5\u30a4\u30ba\u5909\u66f4\u3057\u305f\u308a\u3057\u3066\u3044\u307e\u3059\u3002\u307e\u305f\u3001\u30ad\u30e3\u30f3\u30bb\u30eb\u306e\u30c6\u30b9\u30c8\u3082\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<div style=\"width: 568px;\" class=\"wp-video\"><!--[if lt IE 9]><script>document.createElement('video');<\/script><![endif]--><br \/>\n<video class=\"wp-video-shortcode\" id=\"video-5991-1\" width=\"568\" height=\"482\" preload=\"metadata\" controls=\"controls\"><source type=\"video\/mp4\" src=\"https:\/\/elleneast.com\/wp\/wp-content\/uploads\/programming_topics\/ProgressBar3.mp4?_=1\"><a href=\"https:\/\/elleneast.com\/wp\/wp-content\/uploads\/programming_topics\/ProgressBar3.mp4\">https:\/\/elleneast.com\/wp\/wp-content\/uploads\/programming_topics\/ProgressBar3.mp4<\/a><\/video><\/div>\n<p>&nbsp;<\/p>\n<p>XAML<\/p>\n<pre class=\"lang:xhtml decode:true\">&lt;Window x:Class=\"MainWindow\"\n    xmlns=\"http:\/\/schemas.microsoft.com\/winfx\/2006\/xaml\/presentation\"\n    xmlns:x=\"http:\/\/schemas.microsoft.com\/winfx\/2006\/xaml\"\n    xmlns:d=\"http:\/\/schemas.microsoft.com\/expression\/blend\/2008\"\n    xmlns:mc=\"http:\/\/schemas.openxmlformats.org\/markup-compatibility\/2006\"\n    xmlns:local=\"clr-namespace:WpfApp1\"\n    mc:Ignorable=\"d\"\n    Title=\"MainWindow\" Height=\"135\" Width=\"392\"&gt;\n&lt;Grid&gt;\n    &lt;TextBlock Height=\"23\" Name=\"progressMsg\" Text=\"\u9032\u884c\u72b6\u6cc1\" Margin=\"10, 0, 10, 70\" HorizontalAlignment=\"Stretch\" VerticalAlignment=\"Bottom\" \/&gt;\n    &lt;ProgressBar Height=\"20\" HorizontalAlignment=\"Stretch\" Margin=\"10, 0, 10, 50\" Name=\"progressBar\" VerticalAlignment=\"Bottom\" \/&gt;\n    &lt;Button Name=\"executeBtn\" Content=\"\u5b9f\u884c(_E)\" Margin=\"10, 0, 0, 10\" HorizontalAlignment=\"Left\" VerticalAlignment=\"Bottom\" Height=\"30\" Width=\"100\" \/&gt;\n    &lt;Button Name=\"cancelBtn\" Content=\"\u30ad\u30e3\u30f3\u30bb\u30eb(_C)\" Margin=\"0, 0, 0, 10\" HorizontalAlignment=\"Center\" VerticalAlignment=\"Bottom\" Height=\"30\" Width=\"100\" \/&gt;\n    &lt;Button Name=\"closeBtn\" Content=\"\u9589\u3058\u308b(_Q)\" Margin=\"0, 0, 10, 10\" HorizontalAlignment=\"Right\" VerticalAlignment=\"Bottom\" Height=\"30\" Width=\"100\" \/&gt;\n&lt;\/Grid&gt;\n&lt;\/Window&gt;\n<\/pre>\n<p>&nbsp;<\/p>\n<p>\u30b3\u30fc\u30c9\u30d3\u30cf\u30a4\u30f3\u30c9<\/p>\n<pre class=\"lang:vbnet decode:true \">Imports System.Threading\n\nClass MainWindow\n\n\nDim oCancellationTokenSource As CancellationTokenSource = Nothing '\u500b\u3005\u306e\u30ad\u30e3\u30f3\u30bb\u30eb\u30c8\u30fc\u30af\u30f3\u3078\u306e\u30ad\u30e3\u30f3\u30bb\u30eb\u901a\u77e5\u3092\u7ba1\u7406\u30fb\u9001\u4fe1\u3059\u308b\nDim oCancellationToken As CancellationToken = Nothing '\u30ad\u30e3\u30f3\u30bb\u30eb\u3092\u30ea\u30c3\u30b9\u30f3\u3057\u3066\u3044\u308b\u30bf\u30b9\u30af\u307e\u305f\u306f\u30b9\u30ec\u30c3\u30c9\u306b\u6e21\u3059\u30c8\u30fc\u30af\u30f3\n\n'Progress \u30af\u30e9\u30b9\u3067\u4f7f\u3046\u9032\u6357\u30c7\u30fc\u30bf\nClass progressClass\n    Friend progress As Integer = 0\n    Friend message As String = \"\"\n    Sub New(_progress As Integer, _message As String)\n        progress = _progress\n        message = _message\n    End Sub\nEnd Class\n\n\n\n'\u300c\u5b9f\u884c\u300d\u30dc\u30bf\u30f3\nPrivate Async Sub executeBtn_Click(sender As Object, e As RoutedEventArgs) Handles executeBtn.Click\n\noCancellationTokenSource = New CancellationTokenSource() '.Cancel \u3055\u308c\u305f\u3068\u304d\u306e\u72b6\u614b\u3092\u30ea\u30bb\u30c3\u30c8\u3059\u308b\u305f\u3081\uff08\u7d42\u4e86\u6642\u306b .Dispose \u3057\u3066\uff09New \u3057\u76f4\u3059\u3002\noCancellationToken = oCancellationTokenSource.Token\n\n'\u30c6\u30b9\u30c8\u7528\u306e\u30d5\u30a1\u30a4\u30eb\u540d\u3092 100 \u500b\u4f5c\u6210\nDim files As New List(Of String)\nFor i As Integer = 0 To 99\n    files.Add(\"File\" &amp; i + 1 &amp; \".txt\")\nNext\n\n'Progress \u30af\u30e9\u30b9\u306e\u9032\u6357\u5831\u544a\u306f New Progress \u3055\u308c\u305f\u30b3\u30f3\u30c6\u30ad\u30b9\u30c8\u306b\u5bfe\u3057\u3066\u884c\u308f\u308c\u308b\u306e\u3067\u3001\u975e\u540c\u671f\u51e6\u7406\u3092\u958b\u59cb\u3059\u308b\u524d\u306b New \u3057\u3066\u304a\u304f\u3002\nDim progress_files = New Progress(Of progressClass)(AddressOf showProgress_files)\n\nCall \u30dc\u30bf\u30f3\u3092\u7121\u52b9\u5316\n\nTry\n\n    '\u5225\u30b9\u30ec\u30c3\u30c9\u3067\u975e\u540c\u671f\u51e6\u7406\n    Dim bContinue As Boolean = Await Task.Run(Function() \u8907\u6570\u30d5\u30a1\u30a4\u30eb\u306e\u51e6\u7406(progress_files, files))\n    Me.progressMsg.Text = \"\u51e6\u7406\u304c\u5b8c\u4e86\u3057\u307e\u3057\u305f\"\n\nCatch ex As OperationCanceledException\n\n    '\u30e6\u30fc\u30b6\u30fc\u304c\u30ad\u30e3\u30f3\u30bb\u30eb\u3057\u305f\n    Me.progressMsg.Text = \"\u30ad\u30e3\u30f3\u30bb\u30eb\u3055\u308c\u307e\u3057\u305f\"\n\nCatch ex2 As Exception\n\n    Me.progressMsg.Text = \"\u4f55\u304b\u30a8\u30e9\u30fc\u304c\u8d77\u304d\u305f\u307f\u305f\u3044\"\n\nFinally\n\n    oCancellationTokenSource.Dispose\n    oCancellationTokenSource = Nothing\n\nEnd Try\n\nCall \u30dc\u30bf\u30f3\u3092\u6709\u52b9\u5316\n\nEnd Sub\n\n\n\nPrivate Function \u8907\u6570\u30d5\u30a1\u30a4\u30eb\u306e\u51e6\u7406(progress_files As IProgress(Of progressClass), files As List(Of String)) As Boolean\n\n'UI \u30b9\u30ec\u30c3\u30c9\u3068\u306f\u5225\u30b9\u30ec\u30c3\u30c9\u306a\u306e\u3067\u3053\u306e\u95a2\u6570\u5185\u304b\u3089\u76f4\u63a5 UI \u306b\u306f\u30a2\u30af\u30bb\u30b9\u3067\u304d\u306a\u3044\uff08Dispatcher.Invoke \u3092\u4f7f\u3048\u3070\u53ef\u80fd\uff09\n\nDim filesTotal As Integer = files.Count\n\nFor i As Integer = 0 To files.Count -1\n\n    Dim progressPercent As Integer = CInt((i + 1) \/ filesTotal * 100) '\u9032\u6357\u7387\n    progress_files.Report(New progressClass(progressPercent, files.Item(i) &amp; \" (\" &amp; (i + 1).ToString(\"N0\") &amp; \"\/\" &amp; filesTotal.ToString(\"N0\") &amp; \")\"))\n\n    System.Threading.Thread.Sleep(100)\n\n    'Call \u30d5\u30a1\u30a4\u30eb\u3054\u3068\u306e\u51e6\u7406(files.Item(i))\n\n    oCancellationToken.ThrowIfCancellationRequested '\u30e6\u30fc\u30b6\u30fc\u304c\u30ad\u30e3\u30f3\u30bb\u30eb\u3057\u305f\u3089\u4f8b\u5916\u3092\u6295\u3052\u308b\n    '\u30c7\u30d0\u30c3\u30b0\u30e2\u30fc\u30c9\u3067\u975e\u540c\u671f\u51e6\u7406\u306e\u4f8b\u5916\u304c\u62fe\u3048\u306a\u3044\uff1f\u3068\u601d\u3063\u305f\u3089 --&gt; https:\/\/elleneast.com\/?p=5918\n\n    '\u4f8b\u5916\u3092\u4f7f\u308f\u306a\u3044\u3084\u308a\u65b9\n    'If token.IsCancellationRequested = True Then\n    '    Return False\n    'End If\nNext\n\nprogress_files.Report(New progressClass(100, \"\"))\n\nReturn True\n\nEnd Function\n\n\n\n'\u9032\u6357\u8868\u793a\u3002\u3053\u306e\u95a2\u6570\u306f UI \u30b9\u30ec\u30c3\u30c9\u3067\u547c\u3073\u51fa\u3055\u308c\u308b\nPrivate Sub showProgress_files(oProgress As progressClass)\n\nMe.progressMsg.Text = oProgress.message\n\nCall showProgress_setValue(Me.progressBar, oProgress.progress)\n\nEnd Sub\n\nPrivate Sub showProgress_setValue(oProgressBar As ProgressBar, progress As Integer)\n\noProgressBar.Value = progress\n\n'\u3053\u308c\u2193\u306f Forms \u306e\u8a71\u304b\u306a\uff1fWPF \u3067\u306f\u3084\u3089\u306a\u304f\u3066\u3082\u5927\u4e08\u592b\u307f\u305f\u3044\u3002\n\n'Vista \u4ee5\u964d ProgressBar \u306e\u5024\u3092\u5909\u66f4\u3057\u3066\u3082\u5373\u5ea7\u306b\u30d0\u30fc\u306b\u53cd\u6620\u3055\u308c\u305a\u3001\u5c11\u3057\u9045\u308c\u3066\u30d0\u30fc\u304c\u4f38\u3073\u3066\u304f\u308b\u3088\u3046\u306b\u306a\u3063\u3066\u3057\u307e\u3063\u305f\u3002\n'\u3053\u308c\u3060\u3068\u5b9f\u969b\u306b\u306f\u51e6\u7406\u304c\u5b8c\u4e86\u3057\u3066\u3044\u3066\u3082\u3001\u30d0\u30fc\u304c\u6700\u5f8c\u307e\u3067\u4f38\u3073\u3066\u306a\u3044\u306e\u3067\u51e6\u7406\u304c\u672a\u5b8c\u4e86\u306b\u898b\u3048\u308b\u3053\u3068\u304c\u3042\u308b\u3002\n'\u8a2d\u5b9a\u3057\u305f\u5024\u304c\u5373\u5ea7\u306b\u30d0\u30fc\u306b\u53cd\u6620\u3055\u308c\u308b\u3088\u3046\u306b\u3059\u308b\u305f\u3081\u3001\u4e0b\u8a18\u306e\u3088\u3046\u306a\u5909\u306a\u3053\u3068\u3092\u3057\u3066\u3044\u308b\u3002\n'https:\/\/dobon.net\/vb\/dotnet\/control\/pbdisableanimation.html\n\n'If progress &lt; oProgressBar.Maximum Then\n'     oProgressBar.Value = progress + 1\n'     oProgressBar.Value = progress\n'Else\n'     oProgressBar.Maximum += 1\n'     oProgressBar.Value = progress + +1\n'     oProgressBar.Value = progress\n'     oProgressBar.Maximum -= 1\n'End If\n\nEnd Sub\n\n\n\nPrivate Sub \u30dc\u30bf\u30f3\u3092\u7121\u52b9\u5316\nMe.executeBtn.IsEnabled = False\nMe.closeBtn.IsEnabled = False\nEnd Sub\n\n\n\nPrivate Sub \u30dc\u30bf\u30f3\u3092\u6709\u52b9\u5316\nMe.executeBtn.IsEnabled = True\nMe.closeBtn.IsEnabled = True\nEnd Sub\n\n\n\n'\u300c\u9589\u3058\u308b\u300d\u30dc\u30bf\u30f3\nPrivate Sub closeBtn_Click(sender As Object, e As RoutedEventArgs) Handles closeBtn.Click\n\nMe.Close\n\nEnd Sub\n\n\n\n'\u300c\u30ad\u30e3\u30f3\u30bb\u30eb\u300d\u30dc\u30bf\u30f3\nPrivate Sub cancelBtn_Click(sender As Object, e As RoutedEventArgs) Handles cancelBtn.Click\n\nIf oCancellationTokenSource IsNot Nothing Then\n\n    oCancellationTokenSource.Cancel '\u30e6\u30fc\u30b6\u30fc\u304c\u30ad\u30e3\u30f3\u30bb\u30eb\u3057\u305f\n\nEnd If\n\nEnd Sub\n\nEnd Class\n<\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>VB.NET \u3067\u30d7\u30ed\u30b0\u30ec\u30b9\u30d0\u30fc\u3092\u975e\u540c\u671f\u3067\u52d5\u4f5c\u3055\u305b\u3066\u307f\u307e\u3059\u3002 VB.NET \u306b\u304a\u3051\u308b\u975e\u540c\u671f\u51e6\u7406\u3001\u30ad\u30e3\u30f3\u30bb\u30eb\u51e6\u7406\u3001Progress \u30af\u30e9\u30b9\u306e\u4f7f\u3044\u65b9\u7b49\u306e\u30b5\u30f3\u30d7\u30eb\u306b\u306a\u3063\u3066\u307e\u3059\u3002C# \u306e\u60c5\u5831\u306f\u305f\u304f\u3055\u3093\u898b\u3064\u304b\u308b\u3051\u3069\u3001VB.NET \u306e &#8230; <\/p>\n","protected":false},"author":1,"featured_media":2656,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[57],"tags":[60,62],"class_list":{"0":"post-5991","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-57","8":"tag-vb-net","9":"tag-wpf"},"_links":{"self":[{"href":"https:\/\/elleneast.com\/index.php?rest_route=\/wp\/v2\/posts\/5991","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/elleneast.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/elleneast.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/elleneast.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/elleneast.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5991"}],"version-history":[{"count":3,"href":"https:\/\/elleneast.com\/index.php?rest_route=\/wp\/v2\/posts\/5991\/revisions"}],"predecessor-version":[{"id":7460,"href":"https:\/\/elleneast.com\/index.php?rest_route=\/wp\/v2\/posts\/5991\/revisions\/7460"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/elleneast.com\/index.php?rest_route=\/wp\/v2\/media\/2656"}],"wp:attachment":[{"href":"https:\/\/elleneast.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5991"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/elleneast.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5991"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/elleneast.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5991"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}