|
You have to "tune the timing" of sending an SMS?? I've never heard of anyone ever having to do that. It sounds like you have a serious design flaw in your app.
|
|
|
|
|
I am having trouble getting my head around a Threading problem I have. I want to process some data while displaying a message stating that the data is being processed.
So hear is some sample code that I have been trying.
thrd = New Thread(AddressOf ThreadProc)
thrd.start()
'process data
thrd.abort 'I want a way to know when process data is done.
Private Sub ThreadProc()
Dim load As New Loading
load.ShowDialog()
End Sub
But, When my process is done the showdialog does not go away until I click in the form or move the mouse. Any suggestions on how to do this. How can I get the showdialog to go away?
|
|
|
|
|
Hi Cory,
this is so wrong.
It is almost always a bad idea to abort a thread since you typically don't know what it is doing at that specific point in time, and resources may be locked, memory allocated, etc.
In this particular case, aborting the thread stops the message pump that was keeping the
progress dialog alive (the pump is a loop running inside the ShowDialog method); by aborting the thread, the dialog just sits there, completely dead, what piece of code would be responsible of removing it?
The correct way to handle this is by:
1. putting the time-consuming stuff in a thread or a BackgroundWorker (BGW are available since .NET 2.0), which you want to run to completion, hence no abort necessary;
2. showing the progress dialog in the normal manner, without using an extra thread.
3. letting the thread/BGW signal the progress dialog when it is done (this obviously requires caution about cross-thread violations, automatically solved by BGW, and solvable with Control.InvokeRequired/Control.Invoke on regular threads.
4. you may add real progress indication in the dialog; again a BGW is helping there
5. you may want to add a Cancel button; the proper way to handle a cancel request is by having the background job done in a collaborative way, typically by periodically checking a "please cancel" flag. Don't use Thread.Abort if you don't have to!
I strongly suggest you study some BackgroundWorker examples.
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
Hi,
I am experiencing a difficulty to use one the reference (dll) file inside the code page. It is listed under References and also it shows up under the references section in the property page of the project. However when I use Imports .... I was expecting to see its name. Neither I am able to call its name with imports nor I am able to use it explicitly with Dim ax as New ResourceName.
Do you have any idea why? I am using VS2008
Thanks.
What a curious mind needs to discover knowledge is noting else than a pin-hole.
|
|
|
|
|
Double click that dll from references and it will open up in Object Browser. Now see are you using the correct namespace or not.
|
|
|
|
|
I am confused on how to extend a generic type like the KeyValuePair(of TKey, TValue). For example, I want to override the .tostring method, but am confused on what to inherit from to accomplish this.
Could someone nudge me in the right direction?
Any suggestions, ideas, or 'constructive criticism' are always welcome.
"There's no such thing as a stupid question, only stupid people." - Mr. Garrison
|
|
|
|
|
You can inherit two ways depending on how specific your requirements are. Either:
MyGenericKeyValuePair(Of TKey, TValue)
Inherits KeyValuePair(Of TKey, TValue)
or
MyKeyValuePair
Inherits KeyValuePair(Of String, Integer)
If you have only one type of KeyValuePair for which you want to overwrite ToString, option 2 is best.
|
|
|
|
|
Hey Gideon,
Thanks for the response. I def. need method #1 (Of TKey, TValue). When I try this:
Public Class KeyValuePair_Generic(Of TKey, TValue)
Inherits KeyValuePair(Of TKey, TValue)
End Class
I get "Classes can only inherit from other classes."
Any suggestions, ideas, or 'constructive criticism' are always welcome.
"There's no such thing as a stupid question, only stupid people." - Mr. Garrison
|
|
|
|
|
KeyValuePair(Of TKey, TValue) is not a Class but rather a Structure (struct) which means you can't inherit from it. You would need to create your own equivalent Structure (and I would recommend using a Structure rather than a class) and using that instead.
Scott Dorman Microsoft® MVP - Visual C# | MCPD
President - Tampa Bay IASA
[ Blog][ Articles][ Forum Guidelines] Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai
|
|
|
|
|
Roger that. I'll give that a go.
Thanks.
Any suggestions, ideas, or 'constructive criticism' are always welcome.
"There's no such thing as a stupid question, only stupid people." - Mr. Garrison
|
|
|
|
|
I looked in the code behind file but I don't see any code for adding event handlers for controls such as: AddHandler ..., Addressof....
How is this possible if the event handler does not even have the Handles xxx.event at the end of the event handler?
CodingYoshi
Visual Basic is for basic people, C# is for sharp people. Farid Tarin '07
|
|
|
|
|
Did you notice the "WithEvents" clause on those Dim statements?? Did you also notice the "Handles" clause on the end of the event handler headers?? Read this[^] and you'll know how it works.
Dim WithEvents someVariable As New Button
.
.
.
Private Sub ButtonClickHander(..., ...) Handles someVariable.Click
|
|
|
|
|
All this inconsistency between C# and VB.NET makes things more confusing. It has never helped me.
CodingYoshi
Visual Basic is for basic people, C# is for sharp people. Farid Tarin '07
|
|
|
|
|
That's starting to change...
|
|
|
|
|
Hello, all.
Is it possible to get the name of a local variable from a reference to the variable? For example, I can get the names and values of a calling function's parameters like this:
Dim frame As New StackFrame(1)
Dim pInfos() As ParameterInfo = frame.GetMethod().GetParameters()
Is there some way to get the same information for a calling function's local variables? This is kind of what I have in mind:
Sub SomeSub()
Dim count As Integer = 10
Dim average As Single = 45.67
LogLocalVariables(count, average)
End Sub
Sub LogLocalVariables(ByVal var1 As Object, ByVal var2 As Object)
' I can get each variable's type like this:
Dim mBody As MethodBody = GetType(Form1).GetMethod _
("SomeSub").GetMethodBody()
Dim varList As ObjectModel.ReadOnlyCollection(Of LocalVariableInfo) = _
mBody.LocalVariables
' But what I really want is info like this:
' count = 10
' average = 45.67
End Sub
Thanks.
--Clay
|
|
|
|
|
Hi Clay,
AFAIK names of local variables are not available.
names of parameters (method arguments) are available, although I am not sure why that is.
the only thing that needs to be available (for reflection to work as intended) is the public
class members, nothing local.
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
Yeah, I was afraid of that. Thanks.
--Clay
|
|
|
|
|
Luc Pattyn wrote: names of parameters (method arguments) are available, although I am not sure why that is.
The names of parameters are available because they make using an API orders of magnitude easier. Otherwise Intellisense would not be able to provide you with the parameter names and you would just have to know which parameter is which. If the XML documentation is included, you could argue that Intellisense could determine the names from there, but libraries do not always have that documentation.
|
|
|
|
|
Clay Walnum wrote: LogLocalVariables(count, average)
Well, since you're passing the local variable in already, what's the point of going back to the method that called it to figure them out??
Really, you're not the first person to try this. There are easier methods of logging values. One major problem you'll run into attempting to do this is variable scope. For example, you can have a variable that only exists inside a loop in a method, but is out of scope in the rest of the method, either before or after the loop. You can't get the value of a variable that doesn't exist yet or is already dead.
Another problem is Reflection's performance. Reflection is notoriously slow. If you end up trying to log variable values inside of a loop, you'll find that your app's performance may be quite unacceptable.
And yet another issue is what happens when you go from a Debug build to a Release build?? All of this logging code will still be in the release build. How are you going to remove all this code so you don't take a performance hit in the final release? If you use the Debug class, these calls are automatically removed from the Release build. Trace method calls are converted to call equivilent Debug methods (weird!) and are NOT removed from the Release build.
So, pretty much, the best method to use with the least maintenance is directly calling Debug.WriteLine in your code where needed.
|
|
|
|
|
Thanks for the input. I'm doing this more to experiment with Reflection than actually creating a custom debugging system. It just seems that there ought be be a way to get the name of a variable, as well as the value, other than passing them both as arguments, like this:
LogVariable("VarName", VarName)
But I guess not.
--Clay
|
|
|
|
|
Yes, I fully agree, in C# that is the one thing I miss most from C's pre-processor,
where you could create a one-argument macro that uses it twice, once for the name, once
for the value.
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
One major problem with that approach is that the LogLocalVariables method doesn't get references to the local variables at all. What it gets is references to two newly created objects on the heap, that contains copies of the values that the local variables had when calling the method. There is no association at all between those object and the local variables, so it's impossible to use the references to get any information at all about the actual variables.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
One major problem with that approach is that the LogLocalVariables method doesn't get references to the local variables at all.
Yes, I understand that the arguments should have at least been passed as ByRef, which would have given the called sub at least access to the same memory location. Just an oversight. But even if the args are ByRef, there's no way to get the names of the passed variables.
Thanks for your comments.
--Clay
|
|
|
|
|
If I Understand your request clearly, here is how I did this
Dim objDict
objDict = CreateObject("scripting.dictionary")
Dim Var1 As String = "ABC"
Dim Var2 As Integer = 1000
objDict.Add("var1", Var1.ToString)
objDict.Add("var2", Var2.ToString)
Dim I As Integer
For I = 1 To objDict.Count
Debug.WriteLine(objDict.Keys(I - 1) & "=" & objDict.Items(I - 1))
Next
hth
Samir R. Ibrahim
|
|
|
|
|
Hi, Samir.
Thanks for the code. You're still kind of doing what I was trying to get around, though, which is having to pass both a variable name and its value to a method. I'd like to be able to get the variable name from the variable itself, much as you can do using Reflection on a method's parameters.
Still, I appreciate your efforts. I'm amazed at the number of quick and intelligent responses I've gotten to my question. This has been my favorite site for sample code for a long time, and now I see that the forum is just as good.
Thank you all!
--Clay
|
|
|
|