|
Thank you everybody ... am working on ur suggestions.
|
|
|
|
|
hi,
im new to windows mobile development on .net.
im using:
visual studio pro 2008;
windows 7
Windows mobile SDK 5.0
On the File menu, i select New->Project. In the Project Types pane on the left, expand Visual C# and select Smart Device. In the Templates pane on the right, select Smart Device Project and click OK. When the Add New Smart Device Project wizard pops up, i select Device Application and click OK.
so i start debugging and ran the emulator. i open windows media player wanting to play some songs. how do i use the media player to open songs from my computer or import the songs from my computer to the emulator?
|
|
|
|
|
|
hi all,
i am having two forms , form1 and form2. Form1 is having 3 labels , i have to fill all these levels from form2. I am calling form2 via form1 . Can someone help me please , how to fill labels of form1?
Thanks,
Vikas
vikas da
|
|
|
|
|
1. If you want to set the text in some event, have a delegate and handle that event in Form1. There you can set the text.
2. Have static properties for the label text and set them in the Form2. Static because then you will not need to pass the current instance of Form1.
50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!
|
|
|
|
|
its not on some event...when i say ok on form 2 the values shown on form2 should comeback and reflect on form1 and form 2 should be closed after that...
its something like i have a connect button..on click of that button it opening a page and there u can select a database and its instances. when u say ok on the form these values database name and instances should be set on base form where connect button resides.
vikas da
|
|
|
|
|
Have two static properties for label text in your form1. In the OK button click event, set these to the values you want.
In form1,
public static string Label1Text{
get{
return this.label1.Text;
}
set{
this.label1.Text = value;
}
}
In form2, inside OK button click event,
Form1.Label1Text = "some value";
}
}
50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!
|
|
|
|
|
There are two problems here:
1) Declaring the property as static means it won't compile - static properties have no "this" object.
2) While this method will work with a little tweak, it is not good practice (and it's best to use good practice as early in the learning process as possible, or it gets harder to break the bad habits).
A better way to do it it to signal a "data changed" event from the button form to the label form:
Form 1:
private void Form1_Load(object sender, EventArgs e)
{
Form2 f2 = new Form2();
f2.Changed += new EventHandler(Changed);
f2.Show();
}
private void Changed(object sender, EventArgs e)
{
ChangedArgs ca = e as ChangedArgs;
if (ca != null)
{
label1.Text = ca.strData;
}
else
{
label1.Text = "Fired!";
}
}
Form2:
public event EventHandler Changed;
private void button1_Click(object sender, EventArgs e)
{
EventHandler eh = Changed;
if (eh != null)
{
eh(this, new ChangedArgs("Hello!"));
}
}
Additional:
public partial class ChangedArgs : EventArgs
{
private string _strData;
public string strData
{
get { return _strData; }
set { _strData = value; }
}
public ChangedArgs(string str)
{
_strData = str;
}
}
The ChangedArgs class allows you to transfer all the relevant data Form2 needs to pass to Form1.
All those who believe in psycho kinesis, raise my hand.
|
|
|
|
|
OriginalGriff wrote: 1) Declaring the property as static means it won't compile - static properties have no "this" object.
Correct. Typed here itself so missed out.
OriginalGriff wrote: it is not good practice
May I ask why? I think properties are meant share data between the forms. In case you think exposing controls properties are not a good practice, then I had mentioned use of delegates in my first reply. I would handle the OK button click event in the Form1 and either pass the values through Tag property of the button or would have a property in the form2 which can be accessed in the Form1.
50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!
|
|
|
|
|
Thanks Danish for the help and suggestion...i got it now working..
vikas da
|
|
|
|
|
d@nish wrote: May I ask why?
OOP is based around a small number of key concepts - how many depends on who you talk to - but most agree that important ones are Encapsulation, Modularity, and Abstraction.
Public properties do provide these, yes, but only in one direction - from the outside world to the class containing the property definitions.
So, if Form1 consumes the info and Form2 generates it as in the earlier posts, handling it with public properties needs:
Form2:
form1instance.property = value;
Form1:
property set method - Handle value.
What happens if you have two copies of Form1, both of which need to consume the data?
Form2:
form1instance1.property = value;
form1instance2.property = value;
Form1:
property set method - handle value.
Yes - you have to change the data provider to cope with the new instance of the data consumer. The same thing happens if you want to reuse the data provider for some other purpose which does not need a data consumer. Either you have to change the provider to cope with the lack of a consumer, or you have to provide a consumer which does nothing to cope with the provider.
If instead you throw an event "I have data to be consumed" and subscribe to that event as needed in your consumers, you can have as many consumers of the data as you like without changing consumer or provider. This includes zero consumers, that's why the "if (ca != null)" in my original post was there.
There is nothing wrong with using public properties - I do on a regular basis - but when the event handling mechanism is both there and simple to use, it is worth getting used to as early as possible.
Does that make sense? (It was typed quickly and may be a little impenetrable)
All those who believe in psycho kinesis, raise my hand.
|
|
|
|
|
Well said! Using constructor overloads to pass instance data, or static objects/properties on instances to avoid using events and delegates is far too common. Unfortunately, custom events and event args is quite confusing for a noob so the quick and dirty is often adopted and even recommended
For anyone else that comes accross this - it's not that hard to do it properly!
public class YourClass
{
public event EventHandler<YourEventArgs> YourEvent;
private int yourProperty;
public int YourProperty
{
get { return yourProperty; }
set
{
if (yourProperty != value)
{
yourProperty = value;
OnYourEvent(new YourEventArgs(yourProperty));
}
}
}
protected virtual void OnYourEvent(YourEventArgs e)
{
EventHandler<YourEventArgs> eh = YourEvent;
if (eh != null)
eh(this, e);
}
}
public class YourEventArgs : EventArgs
{
private int yourProperty;
public YourEventArgs(int parameter)
{
this.yourProperty = parameter;
}
public int YourProperty
{
get { return yourProperty; }
}
} An example of useage
public class Consumer
{
private YourClass yourClass;
public Consumer()
{
yourClass = new YourClass();
yourClass.YourEvent += new EventHandler<YourEventArgs>(yourClass_YourEvent);
yourClass.YourProperty++;
}
private void yourClass_YourEvent(object sender, YourEventArgs e)
{
Console.WriteLine(e.YourProperty);
}
}
Dave
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
OriginalGriff wrote: Does that make sense?
Yes, it does. I have seen a lot of data sharing posts here and I almost always provide both the mechanisms by which this can be done. i.e. delegates and properties. Then, it is up to the OP to choose. I prefer it that way since it is their application and they are supposed to understand it, not me. For instance, the multiple instance problem you mentioned is something that only OP would know is possible or not.
Although, I do not prefer having a new event when one can very well achieve the thing using existing ones. Like in this case, handling button click event in the Form1 itself should be sufficient.
As far as having properties is concerned, exposing the controls of the page/form is something I do not prefer. So if I was OP, I would have handled OK button click in Form1. Still, as I had said before, it is his/her application and it is up to him/her to decide which approach is better.
50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!
|
|
|
|
|
Thanks OriginalGriff
it worked well i guess o am using callback functionality here to post the data back to parent page...
Thanks once again
vikas da
|
|
|
|
|
Hi,
I'm running into a very strange behavior of HttpWebRequest.BeginGetResponse().
Instead of returning immediately, and executing the request in a new Thread from the ThreadPool, the method blocks, and the request is executed in the same thread. Actually, it behaves like HttpWebRequest.GetResponse().
Basically I do a very simple task, in which I call a big number of web requests and run them asynchronously:
private void scheduleMyWebRequests()
{
for (int i = 0; i < someNumber; i++)
{
…
IAsyncResult result = httpWebReq.BeginGetRespons(processMyData, state);
ThreadPool.RegisterWaitForSingleObject(result.AsyncWaitHandle, timeoutCallback, state, timeout, true);
}
}
private void processMyData (IAsyncResult result)
{
...
...
if(noMoreRequestsToProcess)
callAnotherMethodToContinue()
}
This code works perfectly when the web requests use HttpMethod.GET
All the requests run asyncronously.
However, when I started using requests which are HttpMethod.POST something strange happens:
After the first BegineGetResponce() the control doen't return immediately.
Instead, the same thread starts runing the processMydata() method. Only when this method finishes, the control returns to the calling method.
All my web requests are performed syncronously rather then asyncronously (I've dumped the Thread's Id and all the calles use the same Thread Id).
When I use HttpMethod.Get I can see that indeed, each request uses a different Thread Id, as expected.
Does anyone have a clue why is this happening?
P.S. the cause is not an unhandled exception. I've already checked…
Tnx
Roy
|
|
|
|
|
Have you read the relevant documentation? One page of it says:
"Your application cannot mix synchronous and asynchronous methods for a particular request. "
maybe that rings a bell?
|
|
|
|
|
Yes, I've read the document and i'm well aware of this fact.
I'm not performing any syncronous requests at all. Only asyncronous.
Tnxanyway...
|
|
|
|
|
Hi
This my connectionstring to my sql database that the database file position is : C:\Users\hossein\Desktop\MyProject\MyProject\bin\Debug\Data
string constr =
"Data Source=.;DataBase="+System.Windows.Forms.Application.StartupPath+"\\Data\\mydatabase.mdf;"
+"Integrated Security=true";
sqlconnection con=new sqlconnection();
con.open();
I have error when compiler want to compile "con.open()" and error is "compiler can't open mydatabase"
what should i do?
|
|
|
|
|
While adopting exception handling techniques, is the compiler able to give correct answers or we just handle those conditions by printing an error message using longjmp() etc?
Like in the following program the square of 1000000 would overflow? So can the compiler print its original result? And also in other cases such as " ArrayTypeMismatchException ", what technique is adopted to handle it?
int square(int i)
{
return i * i;
}
void f()
{
checked
{
int i = square(1000000);
}
}
|
|
|
|
|
Razanust wrote: checked
{
int i = square(1000000);
}
Will throw an Exception; you should catch it and display a message or something.
|
|
|
|
|
My need is to schedulle to run a C# application once a day for some days of the week
And I provide an UI to set those days
So I was trying to find out if the best way is to make a service to do that or to programaticaly try to make a new Windows task to run the app as an exe
Thanks for your help / suggestion
Olivier
|
|
|
|
|
CP link [^].
There's nothing left in my right brain and nothing right in my left brain. |
|
|
|
|
|
you could tell Windows to run it once a day, then in your code skip the days that you don't want any action taken. day selection information could be kept in a settings file, a separate file, the registry, whatever, which some app could display and modify through a GUI.
|
|
|
|
|
Thank you
Very nice Idea !!
Of course I already have my own setting file !
Unfortunately the user wants also to set the time for the given days
|
|
|
|
|
Thank you Luc
Yes I know that link but I do not feel confident with that solution
1- I can't compile it because the post compile event wants to run mt.exe and I don't know why ?
2- As I can see it uses an uggly old fashion dos interface
3- At the first sight I thougt that the goal for that app was to create or edit Windows .job files and let Windows scheduller do the job. If so I do not understand why it needs 7 files of about 100k of source code to do that ?
I'm afraid that this is just another scheduller !
But till now it's purpose is not clear to me ?
|
|
|
|