|
Hi All,
As part of my project i created a MFC dialog application which broadcasts a user defined windows message.
I have a service that is created in C# and i want this service to listen to the broadcasted message.
How can i listen for a windows message in service. Any sample will be helpfull.
Thanks All
|
|
|
|
|
This is just a suggestion...but have you considered sending the message in a more standardized way, like with MSMQ? With MSMQ, your not bound to the old windows messaging system, and you can host your service and message queue on different boxes.
|
|
|
|
|
Oftentimes we load rows from the database into objects and the objects end up having a complex network. For example, customer can have 1 or many orders, orders can have 1 or many items, items can have 1 or many suppliers and the chain can continue.
Is it better to
1. Pass the parent to the child object in the constructor?
2. Pass only the id of the parent to the child constructor?
3. Pass either 1 or 2 but use properties instead?
Or
4. All of the above are no good.
|
|
|
|
|
If you really need to pass this data then only the parentID should be needed so 2.
3 using 2 should obly be used if the child's parent could potentially change. If not, then the parentID if it's needed as a property should be readonly which would only leave 2.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
Hi everyone,
Im having a wierd problem.
I have an application with several forms thats works perfectly great. the problems appears when i lock my user (windows+L). when im logging in again after the lock somehow my forms are not repainted.
for more info: i checked for the paintig of my forms by moving other windows on them and minimize maximize them and it works great.
Anyone have any idea how windows lock effects my application?
i need your help quickly....
|
|
|
|
|
Are you using custom OnPaint, WPF, or anything fancy?
Need software developed? Offering C# development all over the United States, ERL GLOBAL, Inc is the only call you will have to make.
If you don't ask questions the answers won't stand in your way.
Most of this sig is for Google, not ego.
|
|
|
|
|
I am having problems with merging my tables using DataTable.Merge(). The datasets that I am passing contains roughly 200k rows. I tried merging 3 datasets with this code and the memory usage when .Merge is called is outrageous. it goes from 91M to 1.3g of Ram - then an OutOfMemoryException is called. Most of the datasets only have 200k rows in them, which shouldnt be that much.
Is this normal memory usage for that many rows? Is there an alternative that will be fast and memory friendly?
Thanks.
|
|
|
|
|
DataSets suck. No application should ever have more than a few hundred rows in memory ever. I usually use a database for that type of merging or streams and sorting algorithms. The problem with the dataset is that your 200k rows are in memory.
Need software developed? Offering C# development all over the United States, ERL GLOBAL, Inc is the only call you will have to make.
If you don't ask questions the answers won't stand in your way.
Most of this sig is for Google, not ego.
|
|
|
|
|
I understand what you are saying, however, in my case I have no other alternative but to use DataTables and DataSets.
The application I have gives us a list of available datasources (some from DB but could be a file)
The user has the option to combine two available datasources together to create one datasource.
At first, I went the long way of doing the merging by looping through each row and each column.
This was a bad idea for many reasons.
I found DataTable.Merge and passed in each dataset
Seemed quick and handled my schemas for each dataset.
But the draw back is memory.
So, can you (or someone) offer another way of doing this? Something fast and easy on the memory?
|
|
|
|
|
Hrmm,
If you consider that each data source would have unique tables and thus unique rows you could write each data source to the file system, use an Xml Streaming Reader and Writer and then create the new file as a combination of the other two. It is definitely a non-standard method but may work, would definitely be fast.
Need software developed? Offering C# development all over the United States, ERL GLOBAL, Inc is the only call you will have to make.
If you don't ask questions the answers won't stand in your way.
Most of this sig is for Google, not ego.
|
|
|
|
|
hmm, not a bad idea. I'll try that route real fast and see where it gets me.
I appreciate the time.
|
|
|
|
|
Sometimes we have items in the database which are mere choices. For example, I have a table as below:
TransportationTypeID Description
==================== ===========
1 Vessel
2 Air
3 Land
I can load these from the database but within my code I might have statements like:
If (medium == "Vessel")
{}
However, I think this is hardcoding. A person needs to know all the descriptions from the table to write statements such as these. Is there an alternative? Should I create dynamic enums for the description?
|
|
|
|
|
The most complete approach is to create a class TransportationType with the members Id and Descrption as ReadOnly properties. Then provide a static enumeration as well as static accessors.
However, to address your question, yes, "Vessel" would be hard-coding. Also, it would be better to check against the Id number if it so exists than the textual description. You would be surprised how often then get misspelled.
Need software developed? Offering C# development all over the United States, ERL GLOBAL, Inc is the only call you will have to make.
If you don't ask questions the answers won't stand in your way.
Most of this sig is for Google, not ego.
|
|
|
|
|
I do have a class named TransportationType which encapsulates the records from the table. I even have a TransportationTypeCollection which extends a generic Dictionary<int,> but I still need to know the id and what the description of the record at that id is. I was thinking of putting a global enum to facilitate the description to avoid misspelling but the problem is if a new record is added then I have to change the source code to include the new description and create an enum for it.
I guess some things need to be hard coded and we have to deal with it.
|
|
|
|
|
If adding a new record requires altering source you have a bigger problem.
Need software developed? Offering C# development all over the United States, ERL GLOBAL, Inc is the only call you will have to make.
If you don't ask questions the answers won't stand in your way.
Most of this sig is for Google, not ego.
|
|
|
|
|
But that is exactly what I want to avoid but seems as there is no other option. Just like I mentioned if I need to do something based on the type of the tranportation then what other option do I have? I can not even delegate the responsibility to the TransportationType itself because even then it would need to do a comparison as:
If (transType == "Vessel")
DoThis();
else
{
if (transType == "Air")
DoThat();
}
|
|
|
|
|
public abstract class Transportation{
public abstract void DoThat();
}
public class Air{
...
}
public class Vessel{
...
}
Then abstract the class creation using the Factory pattern. This one and only location could then be used for the hard-coding.
Need software developed? Offering C# development all over the United States, ERL GLOBAL, Inc is the only call you will have to make.
If you don't ask questions the answers won't stand in your way.
Most of this sig is for Google, not ego.
|
|
|
|
|
You missed a bit...make sure you derive from the base Transportation class:
public abstract class Transportation
{
public abstract void DoThat();
}
public class Air: Transportation
{
...
}
public class Vessel: Transportation
{
...
}
|
|
|
|
|
thx
Need software developed? Offering C# development all over the United States, ERL GLOBAL, Inc is the only call you will have to make.
If you don't ask questions the answers won't stand in your way.
Most of this sig is for Google, not ego.
|
|
|
|
|
Enums are helpful, but when trying to avoid 'coupling' they can create more problems than they solve. Remember they are basically a convenient textual representation of a numeric value (int by default) so you could just work with the numeric values thenselves. If you need the string for convenience, you could use a generic list of a class that has a string and an int properties, or a keyvalue pair/dictionary so you always have both available.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
Generally I write an enum to match the table and add a comment that it must be kept in sync with the particular table.
I seem to recall that someone here recently (last few months?) posted about a technique to automatically update the table to match the enum, but I don't think that's quite the best solution.
Ideally the enum would be generated from the database, but how?
Certainly a process by which a code file is generated (at compile time) based on a query could be constructed, but it could cause a full rebuild even when the table doesn't change, so that may not be very palatable to some.
Emitting the enum at runtime doesn't seem like a workable solution because you wouldn't be able to program against it. (At least not until .net 4.0?)
|
|
|
|
|
That is indeed hard coding...and its best to avoid it whenever possible. An alternative to a hard coded string, enum, etc., you can use inheritance to solve the problem. Assuming that the TransportationType table is just a lookup of entries that classify records in other tables, you could do something like the following:
abstract class TransportationMedium
{
abstract string Name { get; }
abstract void Transport();
}
class Vessel: TransportationMedium
{
override string Name { get { return "Vessel"; } }
override void Transport()
{
}
}
class Air: TransportationMedium
{
override string Name { get { return "Air"; } }
override void Transport()
{
}
}
class Land: TransportationMedium
{
override string Name { get { return "Land"; } }
override void Transport()
{
}
}
static class TransportationMediumFactory
{
static TransportationMedium Construct(int typeID)
{
switch (typeID)
{
case 1: return new VesselMedium();
case 2: return new AirMedium();
case 3: return new LandMedium();
}
}
static TransportationMedium Construct(string type)
{
switch (type)
{
case "Vessel": return new VesselMedium();
case "Air": return new AirMedium();
case "Land": return new LandMedium();
}
}
}
class Program
{
void Main()
{
int mediumType = 0;
string intput;
Console.Write("Select medium (1=Vessel, 2=Air, 3=Land): ");
input = Console.ReadLine();
mediumType = Convert.ToInt32(input);
TransportationMedium medium = TransportationMediumFactory.Construct(mediumType);
Console.WriteLine("You chose " + medium.Name + " as your transportation medium.");
medium.Transport();
}
}
The factory in the implementation above still "hard codes" strings and ID's. This hard coding is centralized, and may be sufficient and maintainable if your application is small. If you need things to be more dynamic, you could easily pull out the mapping between type codes and ID's and the class implementations out into a configuration file, and change the factory implementation to dynamically, rather than statically, create the appropriate type via configuration. Then all hard coding is eliminated.
|
|
|
|
|
In a dialog box scenario this problem isn't evident. But if you have a MDI for and you want to open a form and get the data back to the mdi form you have a problem because you can't do a dialog and even if you could it would defeat the purpose of an MDI. So I was told to fire an event pack to the parent, but how to access the parent from the child especially since I thought that the child doesn't even know the parent
|
|
|
|
|
Why should the child not know its parent?
And what does that have to do with "fire an event back to the parent"; the child would merely raise the event, handling it is up to the parent.
|
|
|
|
|
ok well by firing i mean you are going to have the following line of code
this.uxBtnCreateOrder.Click += new System.EventHandler(this.CreateOrder_Click);
Now I am quite weak in custom events but isn't this where you decide to where the event will go? So I can't figure out how to send this to the parent.
|
|
|
|