|
Hi,
I have a question about threading. I am just starting on C# and this has me confused. In the example below the 2 threads execute a program that counts to 1000.
{
Thread t1 = new Thread(new ThreadStart(Incrementer) );
Thread t2 = new Thread(new ThreadStart(Decrementer) );
// start the threads
t1.Start( );
t2.Start( );
}
public void Incrementer( )
{
for (int i =0;i<1000;i++)
{
Console.WriteLine(
"Incrementer: {0}", i);
}
}
But if i wanted to use this function instead, how would i do that as i keep getting an error in thread initialization.
public void Incrementer(int n )
{
for (int i =0;i
|
|
|
|
|
I'm a newbie myself, but my understanding is that the parameter passed to ThreadStart() has to have the signature
void MethodName();
Also, please use the PRE tags so your post looks better and makes it easier for people to help you.
Cheers,
Vikram.
I don't know and you don't either.
Militant Agnostic
|
|
|
|
|
If you want to pass some value to the thread,
this can be achieved by writing a separate class,
create a property for the value that u want to set,
write the thread in that class
Initialise an object of that class and call a method in which
u can start the method,
set the value before u start the thread,
and then start the thread.
Hope u get it and that works for u.
Regards,
pramod
|
|
|
|
|
And please post the error message next time.
--------------------------------------------------------
Q:What does the derived class in C# tell to it's parent?
A:All your base are belong to us!
|
|
|
|
|
What C# tools & or version do I need if I want to develope software for cellphons??
|
|
|
|
|
First of all you need to contact the Cell Phone manufactuer to determine 1) what requirements and limits are imposed by the architecture, 2) is there a SDK available, 3) does the software you are intending to build already exist, and finally, do you need a license to deploy?
Most cell phone vendors as you can imagine would not take kindly to their phone being used as an open development platform. In fact, lets say you jump through the necessary hoops to get started, you almost certianly be required to have your sofware certified to run on the phone os. Deployung an aplication without permission is definitely a legal mistake. Ever take the time to read your cell phone contract?
One final note, Java is the preferred development language because of specialized VMs that have been ported to the Motorola chipsets. While Java is not just like C#, the similarities are pretty close in terms of streams, sockets, and event handling.
If you are still interested in 3G software, you might start investigating the new Smart Phones touted by Bill Gates. Since the objective is to have Windows CE as the platform you will have an opportunity to do some embedded development for whatever features phone vendors offer in conjunction with the tools Microsoft offers.
Mike Luster
CTI/IVR/Telephony SME
|
|
|
|
|
Hi all,
I was wondering if there is something out there that would enable me to create a plugin tool for IE in C#. What I need is the plugin to extract data from HTML files that the user is viewing, each time a URL is typed in or a hyperlink is followed.
sim
|
|
|
|
|
Try Bandobjects i guess you may find a solution, You can get the Current HTML
Document From hooking to IE
You have a great article on that in codeproject
http://www.codeproject.com/csharp/dotnetbandobjects.asp
|
|
|
|
|
Greetings,
I really like the new command line parsing in C# and that is separates paramerters by space, it has been very useful. Of course I have a need to grab the command line as a whole as it was sent to the application and not cutup by it's spaces. Is there any way to do this in C#? The result should be the same as you get from command$ in vb. I would love to change the parameter but it's being sent from another aplication which I cannot change. Thank you in advance for any assistance.
Brett
|
|
|
|
|
This returns everything (including the EXE):
System.Environment.CommandLine
|
|
|
|
|
That's ok, it's easily parsed out. Thank you much!
Brettski
|
|
|
|
|
Hi everyone am working on a big school project and is facing a problem. Would really be greatful for help from you.
First a codesnip:
int diameter = 40;
Graphics g;
g = this.webBrowser1.CreateGraphics();
//This method draws a rectangele around the object that the mousepointer are pointing at
//in the webbrowsercontrol
DrawRoundedRectangle(g,x,y,width,height,diameter);
The problem is:
the line:
g = this.webBrowser1.CreateGraphics();
don´t seem to set the webbrowser to the current graphiscs object or anyway It isn´t
possible to draw something on the webbrowser.
if I instead use the line:
g = this.CreateGraphics();
It write on the form, it seems that isn´t possible to write on a Webbrowsercontrol?? someone who knows? Or can it be that the webbeowsercontrol all the time is updated and therfore my rectangel isn´t displayed??
tompa
|
|
|
|
|
Your best bet is to override the onpaint method of the control and add any extra drawing you want there. Good luck.
|
|
|
|
|
I don't think that will work either, especially if the browser is doing any navigating.
You may need to
1. draw the web browser to an in-memory bitmap (see this post[^] for information on how to do that)
2. Draw your custom stuff onto that in memory bitmap.
3. Draw the bitmap to the screen.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: How 'bout a little guitar now?
The apostle Paul, modernly speaking: Epistles of Paul
Judah Himango
|
|
|
|
|
I'm converting a small app from VB.net to C#. While doing so I've noticed something really annoying with the way C# handles namespaces.
In VB.net if I have this code:
Imports System<br />
Public Class Class1<br />
Dim t As Timers.Timer<br />
End Class
it should be the same as this C# code:
using System;<br />
public class Class1<br />
{<br />
private Timers.Timer t;<br />
}
However, The C# compiler throws an error on the Timers.Timer. Even though I have "Using System" specified C# doesn't see that Timers.Timer is part of the System namespace. If I write it all out as System.Timers.Timer it compiles but completely defeats the purpose of using a namespace. The code in VB has no problem seeing Timers.Timer as part of the system namespace.
Is there a way to fix this issue in C# so that it will understand the namespace? Or, is it just another arguing point for people who want to say VB is better than C#?
Thanks,
|
|
|
|
|
In C# you need to make sure you are referencing the right kind of Timers. System.Windows.Forms.Timers and System.Timers provide functionally different classes of timer logic.
In terms of the namespace, make sure you choose the one that suits your application.
BTW, if it were not for Microsoft... "Basic" in all of its various forms would have died off years ago. Funny how to keep it alive they made it more like C and then C++ like. And now that there is a CLR differences are petty, so choose the language you want but consider history first before attempting to bash C#. Each language has its own merits.
Mike Luster
CTI/IVR/Telephony SME
|
|
|
|
|
I new the exact namespace i was shooting for. I wanted the System.Timers. That's why the System is the only item I'm "Using" in my example code. From my understanding this is the exact reason you put "Using System" in your code so you don't have to write out System. in front of everything. My question is more about the namespace problem than a timer.
Also, I'm not trying to bash C# or VB. All those arguments are old and tired. I was just trying to point out that in VB the namespace worked as expected and in C# it did not. I would still like to know how to fix this in C#.
|
|
|
|
|
That Timer belongs to System.Timers namespace, not System.
In C# it worked as expectedly, mayb in VB, it guessed which class that you want to use, which it shouldn't, strictly speaking.
|
|
|
|
|
Hi
Try this
<code>
using System;
namespace MyNamespace
{
public class Class1
{
private Timers.Timer t;
}
}
</code>
Ahmad Shaban
|
|
|
|
|
This code produces the same issue. Timers is not found.
|
|
|
|
|
Hello,
This is a problem I faced a few months ago. Not with basic, but I came from a C++ background. Your problem is that the namespace Timers is not available to you! This sounds strange because the namespace resides in the System namespace which you imported. C# does make all classes in the imported namespace available, but not nested namespaces. You can use an alias to solve the problem, or completely import the namespace:
using Timers = System.Timers;
using System.Timers;
public class Class1
{
private System.Timers.Timer t;
}
Hope this helps.
Behind every great black man...
... is the police. - Conspiracy brother
Blog[^]
-- modified at 3:32 Tuesday 21st March, 2006
|
|
|
|
|
|
|
API Help
Posted: 19 Mar 2006 07:25 PM
Hi, I use this --
[System.Runtime.InteropServices.DllImport("user32", EntryPoint = "FindWindowA")]
private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[System.Runtime.InteropServices.DllImport("user32", EntryPoint = "FindWindowExA")]
private static extern IntPtr FindWindowEx(IntPtr hWnd1, IntPtr hWnd2, string lpsz1, string lpsz2);
[System.Runtime.InteropServices.DllImport("user32")]
private static extern IntPtr ShowWindow(IntPtr hwnd, int nCmdShow);
[System.Runtime.InteropServices.DllImport("user32", EntryPoint = "SetWindowTextA")]
private static extern bool SetWindowText(IntPtr hWnd, string lpString);
[System.Runtime.InteropServices.DllImport("user32")]
private static extern int EnableWindow(IntPtr hWnd, bool bEnable);
[System.Runtime.InteropServices.DllImport("user32", EntryPoint = "GetWindowTextA")]
private static extern int GetWindowText(IntPtr hWnd, string lpString, int nMaxCount);
[System.Runtime.InteropServices.DllImport("user32", EntryPoint = "SendMessageA")]
private static extern int SendMessage(IntPtr hWnd, int wMsg, int wParam, int lParam);
private const int WM_LBUTTONDOWN = 513;
private const int WM_LBUTTONUP = 514;
private const int SW_HIDE = 0;
private const int SW_SHOW = 5;
private const int SW_MINIMIZE = 6;
private const int SW_MAXIMIZE = 3;
private const int SW_SHOWMAXIMIZED = 3;
private const int SW_RESTORE = 9;
public void Changetext()
{
IntPtr Taskbar = FindWindow("Shell_TrayWnd", null);
IntPtr StartButton = FindWindowEx(Taskbar, IntPtr.Zero, "Button", null);
SetWindowText(StartButton, "Blah");
EnableWindow(StartButton, false);
EnableWindow(StartButton, true);
}
To change the text on the start button, and it works fine. But it can only have like 5 letters. could i use SetWindowPos to change the width of the start button, to allow for more letters? I have seen code in other langs that do this, And im pretty sire thats the method they take. If so could I see an example please .
|
|
|
|
|
Hi
I'm very interested in the code in hand here
could you send me the code please
Thanks in advance
Ahmad Shaban
|
|
|
|