程序流程执行 [英] Program flow execution

查看:73
本文介绍了程序流程执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经玩了一段时间的编程,并且已经扩展了我已经工作了一段时间但我对执行流程感到困惑的程序。我目前正在学习如何用Visual Basic编程。



我已经学会了启动单独的线程,以确保程序仍然可用,但我是目前正试图将信息传递给另一个子例程。



我一直试图将呼叫拨入不同区域来调用子例程,但它只是没有似乎要执行那行代码。



如下所示,这是多么简单。



I've been playing around with programming for a little while, and have been expanding on a program I have been working on for a while but I'm confused about the execution flow. I'm currently learning how to program in Visual Basic.

I've learnt about starting separate threads, to make sure the program is still usable, but I'm currently trying to pass through information to another sub routine.

I've been trying to slot the call into different areas to call the sub routine, but it just doesn't seem to get to that line of code to execute.

As per below, this is how simple it is.

Private Sub tcpstartthread()

        textboxestime = New Dictionary(Of RichTextBox, Integer)
        textboxestime.Add(Nothing, 0)
        checkforfiles()
    End Sub





在这个例子中,为什么不进入checkforfiles()例程呢?



我想当谈到执行时,它只会流淌下去?



FYI - 我还没有开始使用事件,因为我还没有调查过如何使用它们。有一种感觉我需要调查它才能使它正常工作。



In this instance, why wouldn't it go to the checkforfiles() routine?

I thought when it comes to execution, it just flows through down the lines?

FYI - I haven't started using events as I haven't investigated how to use them as yet. Got a feeling I will need to look into this to get it to work properly.

推荐答案

如果从程序中取出该代码片段并尝试运行它一个简单的WinForm项目,你会发现行
If you take that code snippet out of your program and try to run it in a simple WinForm project you will find that the line
textboxestime.Add(Nothing, 0)

生成错误

引用:

mscorlib.dll中发生了'System.ArgumentNullException'类型的未处理异常



附加信息:值不能为空。

An unhandled exception of type 'System.ArgumentNullException' occurred in mscorlib.dll

Additional information: Value cannot be null.

这看起来非常合理 - 为什么要将一个项目添加到不包含任何感兴趣内容的字典中?由于该错误,以下行永远不会执行。



也许您真正想做的是

Which seems perfectly reasonably - why would you add an item to a dictionary that doesn't contain anything of interest? As a result of that error the following line is never executed.

Perhaps what you really want to do is

textboxestime = New Dictionary(Of Integer, RichTextBox)

即对于key = 0,没有RichTextBox!



如果在调试时没有看到此错误消息,则意味着调用此代码的任何内容都可能在一个Try-Catch块,Catch中没有任何东西 - 不要这样做,如果你打算使用Try-Catch

I.e. for key = 0 there is no RichTextBox to be had!

If you were not seeing this error message when you were debugging it implies that whatever called this code could be in a Try-Catch block where there is nothing in the Catch - don't do this, always handle the errors if you are going to use Try-Catch

这篇关于程序流程执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆