|
When program loads I start new thread which tries to connect some DB server.
this.Load += new EventHandler(Labels_Load);
private void Labels_Load(object obj, EventArgs ea)
{
Thread th = new Thread(new ThreadStart(myconnect));
th.Start();
}
And I need to load some data to comboBox lastBookings. Is it possible to access some form controls from Threads ?
private void myconnect()
{
mysql.mySqlConnect("localhost", "mydb", "usr", "psw");
lastBookings.DataSource = new string[] { "dsdf", "dsfsd ", "dsfa" };
}
I make a new thread because often there is no connection to DB server. And all net operations (if server is not availiable) slow up programm very much.
|
|
|
|
|
And why would you not be able to do that?
Try and see; the only way to learn...
Q:What does the derived class in C# tell to it's parent?
A:All your base are belong to us!
|
|
|
|
|
no, dont work, but if I do the same:
lastBookings.DataSource = new string [] { "dsdf", "dsfsd ", "dsfa" };
not from a thread all works good.
|
|
|
|
|
The core rule is that you are not allowed to modify UI elements from outside the thread they were created in.
The way to go is to use Invoke or BeginInvoke in this case. Invoke performs the method call synchronously, BeginInvoke is asynchronous.
Regards,
mav
|
|
|
|
|
thank you very much! It helped me very much.
In my example it must be so (if someone will have the same question):
private void UpdateBookings(string[] str)
{
lastBookings.DataSource = str;
}
public delegate void UpdateBookingsCallback(string[] str);
private void myconnect()
{
string[] comboElements = {"el1", "el2", "el3" };
lastBookings.Invoke(new UpdateBookingsCallback(this.UpdateBookings), new object[] { comboElements });
}
-- modified at 6:35 Sunday 22nd January, 2006
|
|
|
|
|
Well I am sorry for missinforming you
Q:What does the derived class in C# tell to it's parent?
A:All your base are belong to us!
|
|
|
|
|
Anyway thanks for your attention to my question
|
|
|
|
|
Hi I have a function in unmanaged(VC++) dll which is accepting a refernce parameter
void check(UInt32& c)<br />
{<br />
c=20;<br />
}
I want to call this function from my managed code(C#)
so i used the following code
class Program<br />
{<br />
[DllImport("samp.dll")]<br />
public static extern void check(ref UInt32 c);<br />
static void Main(string[] args)<br />
{<br />
<br />
UInt32 s = 0;<br />
check(ref s);<br />
<br />
Console.WriteLine(s.ToString ());<br />
Console.ReadLine(); <br />
}<br />
<br />
}
but it shows me the error"Unable to find an entry point named 'check' in DLL 'samp.dll'."
is there any way to call a unmanaged dll's function(which has reference parameter) from managed code without using DLL import?? if yes please send me a sample code.
Thanks in advance
Srini
|
|
|
|
|
You can try using out :
[DllImport("samp.dll")]
public static extern void check(out ref UInt32 c);
Dunno if it works though (maybe only out, no ref?) ...
"..Commit yourself to quality from day one..it's better to do nothing at all than to do something badly.."
-- Mark McCormick || Fold With Us! || Pensieve || VG.Net ||
|
|
|
|
|
I believe both out and ref will work, but ref will cause the compiler to complain if the parameter hasn't been initialized before calling check() .
/ravi
My new year's resolution: 2048 x 1536
Home | Music | Articles | Freeware | Trips
ravib(at)ravib(dot)com
|
|
|
|
|
ok, so i know it's some sort of permission problem i'm having, but i can't quite figure out what exactly i need to do to get this working. my windows service is starting a new Process object and launching an EXE. this exe is not getting called, but as a test i confirmed that i am able to launch things like notepad and perfmon from this service.
i think i know what the problem is, but i just can't figure out how to fix it. my service is set to run under local system, and i believe the EXE i'm running is not running correctly because it needs resources that can only be accessed from the user account. is this correct? i've confirmed my code works by running the same code in a console app, and the exe successfully is called. it just won't get called from my exe!
any ideas?
thax!
|
|
|
|
|
Have you tried setting up the service to run as a specific user account, for instance the account you used to confirm that the EXE would start successfully?
You should only do that as a test, by the way. If it does turn out to be a permission issue, a new account or group should be created with the least necessary permission(s) to use the EXE.
The most exciting phrase to hear in science, the one that heralds the most discoveries, is not 'Eureka!' ('I found it!') but 'That's funny...’
|
|
|
|
|
yeah, i tried running it as the user that i run the exe manually successfully from. still doesn't work. i even tried setting it to networkservice, and that didn't even run at all cuz of permission issues...
what else is there to try??
|
|
|
|
|
Well, are you logging events on the service? If so, are there errors getting logged?
Do you know for certain that the executable is not getting started? I don't know what it is you're trying to do, or what the executable is, so it's hard to make suggestions, but if you don't have some form of logging in place, then I would recommend adding some and seeing if anything comes of it.
Good luck.
The most exciting phrase to hear in science, the one that heralds the most discoveries, is not 'Eureka!' ('I found it!') but 'That's funny...’
|
|
|
|
|
i saw some winsock errors in the eveentlog associated with my service.
theh exe i'm running is an exe that communicates with a server. so it opens up a tcp connection to a remote macine and sends some data...
the fact that this is not easy to get working seems to be a GOOD thing, since this is typical action of some malicious service i would assume...
i've spent a lot of time on this and i'm thinking it might be just easier to communicate with the natice c++ written in win32 code directly. then this way i would avoid haveing to spawn a new process and execute it, which is what's causing these security problems, right?
so i can either covert this win32 exe into a DLL or a com object and talk to it using .net's com interop or dill importing attributes. which one is easier?
-- modified at 11:00 Sunday 22nd January, 2006
|
|
|
|
|
In Tab Control the Tab Dialogs change their position automatically whenever I do a change. Sometimes they change at design time and sometimes at runtime. A very strange behaviour I am experiencing.
Help required.
The Phantom.
|
|
|
|
|
Hi, i'm a newbie at C#, how can i know if a child form was terminated? Let's say that there are 10 child forms and I closed 2 child forms, how can I know that these forms were closed? Thanks
|
|
|
|
|
hello, for those who didnt know an answer to this, i have found an answer, refer to this site, it's really helpful http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=181891&SiteID=1
ciao
|
|
|
|
|
my application closes a a few other applications which have system tray icons using the Process.Kill method. The application is closed succesfully, however they leave thier icons behind in the system tray. Is there any way i coould flush or refresh the system tray of useless icons.
|
|
|
|
|
You shouldn't kill other process except in extreme circumstances. Doing so doesn't give the process a chance to do any cleanup - like remove its tray icons - or worse. The normal way to close another application is to post a WM_CLOSE message to its main window.
Steve
|
|
|
|
|
To answer your question about cleaning up the icons, no there is no way to force the Tray to clean itself up.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
The only way i will refresh is if you point your mouse to the "destroyed" icons...
Q:What does the derived class in C# tell to it's parent?
A:All your base are belong to us!
|
|
|
|
|
Tell the OP, not me. I already know that.
He was referring to a programmatic way of forcing the cleanup.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Hi, I have created the following program first as a console application. Then I created a windows application and copied the class data there. It is shown below. In the console application, I have used the printData() method to output the data of an instance of a Person or Athlete class. I want to do the same, but now that output should be in the label.
Any help would be appreciated.
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace windowsPracticingWithClasses
{
///
/// Summary description for Form1.
///
public class Person : System.Windows.Forms.Form
{
///
/// Required designer variable.
///
private System.ComponentModel.Container components = null;
//My instance variables
private string firstName, lastName;
private int age;
private double height, weight;
private string bankName;
private double bankAccount;
private double balance = 0;
private string squareColor;
# region Properties
//Properties
public string FirstName
{
get { return firstName; }
set { firstName = value; }
}
public string LastName
{
get { return lastName; }
set { lastName = value; }
}
public int Age
{
get { return age; }
set { age = value; }
}
public double Height1
{
get { return height; }
set { height = value; }
}
public double Weight
{
get { return weight; }
set { weight = value; }
}
public string BankName
{
get { return bankName; }
set { bankName = value; }
}
public double BankAccount
{
get { return bankAccount; }
set { bankAccount = value; }
}
public double Balance
{
get { return balance ; }
set { balance = value; }
}
public string SquareColor
{
get { return squareColor ; }
set { squareColor = value; }
}
# endregion
//Custom constructor
public Person(int age, double height, double weight, string bankName, double bankAccount, double balance)
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
this.age = age;
this.height = height;
this.weight = weight;
this.bankName = bankName;
this.bankAccount = bankAccount;
this.balance = balance;
}
//Default constructor
public Person()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
}
#region My Methods
//My Methods
public void makeDeposit(int amount)
{
balance+= amount;
}
public void makeWithdrawal(int amount)
{
balance-= amount;
}
public virtual void printData()
{
Console.WriteLine("\nProfile: \n\nAge: " + this.age);
Console.WriteLine("Height: " + this.height);
Console.WriteLine("Weight: " + this.weight);
Console.WriteLine("Bank Name: " + this.bankName);
Console.WriteLine("Bank Account: " + this.bankAccount);
Console.WriteLine("Balance: " + this.balance);
}
#endregion
///
/// Clean up any resources being used.
///
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
//
// Person
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Name = "Person";
this.Text = "Form1";
}
#endregion
}
class Athlete : Person
{
public string sport;
public Athlete(string sport) : base(23,5.6,120,"Chase",5671234,1000)
{
this.sport = sport;
}
public override void printData()
{
base.printData();
Console.WriteLine("Sport Practicing: " + this.sport);
}
};
class TestClasses
{
///
/// The main entry point for the application.
///
[STAThread]
static void Main()
{
Application.Run(new Person());
Person[] person = new Person[5];
person[0] = new Person(22,5.6,120,"Chase",5671234,2000);
person[0].printData();
Person[] athlete = new Athlete[3];
athlete[0] = new Athlete("Figure Skating");
athlete[0].FirstName = "Sarah";
athlete[0].LastName = "Hughes";
athlete[0].Age = 20;
athlete[0].Height1 = 5.5;
athlete[0].Weight = 120;
athlete[0].BankName = "Chase";
athlete[0].BankAccount = 434324;
athlete[0].Balance = 200;
athlete[1] = new Athlete("Martial Arts");
athlete[1].FirstName = "Kim";
athlete[1].LastName = "Chung";
athlete[1].Age = 21;
athlete[1].Height1 = 5.7;
athlete[1].Weight = 130;
athlete[1].BankName = "Citi";
athlete[1].BankAccount = 212312;
athlete[1].Balance = 300;
athlete[2] = new Athlete("Soccer");
athlete[2].FirstName = "Joe";
athlete[2].LastName = "Tribiani";
athlete[2].Age = 22;
athlete[2].Height1 = 5.6;
athlete[2].Weight = 140;
athlete[2].BankName = "Apple";
athlete[2].BankAccount = 123124;
athlete[2].Balance = 400;
for(int i = 0; i < athlete.Length ; i++)
{
athlete[i].printData();
}
Console.ReadLine();
}
}
}
|
|
|
|
|
I am trying to open a .sln in vs 2005 but the error is:
The application for project ....csproj is not installed.
Make sure the applucation for project type (.csproj) is installed.
Thanks
|
|
|
|