|
We do it all the time and it's fine. Because of the nature of data-binding (such as discovery and the binding itself), it's bound to be a little slower than a tightly-coupled solution, but this can be improved greatly by using strongly-typed DataSet classes, which you can make using VS.NET with a DataSet item (right-click on project or project folder, select Add->Add New Item...->DataSet), or by creating an XML schema and using xsd.exe to generate a strongly-typed DataSet class from the schema (this is basically what VS.NET does, only it uses add-in code that works much the same way, if not used by xsd.exe). A big reason for this is because when you refer to columns by name, a lot of look-ups are performed (more than you might think - use ildasm.exe to view the IL for the System.Data assembly and the relevent classes). When you create a strongly-typed DataSet , those column indexes are known at run-time and binding is faster.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I'm using Strong typed datasets but I'm not binding them to controls other than a datagrid or treeview. So I should wire all controls on form.
Lets say 20 to 25 at most and this should be ok with performance of 25 to 50 users using the app?
Design spec:
10 Winforms - 20 to 25 controls on each
25 to 50 users
JJ
|
|
|
|
|
It would work well for me, but whether or not it works well for your requirements is something only you can judge.
Also, 25-50 people won't be using the app. 1 person will be using one application. 25 people will be using 25 separate instances of an application. Those instances querying against the RDBMS will work just fine on a decent DB machine so long as your queries are written correctly and take locking into account when necessary. That has nothing to do with bindings, which is done per instance of the application.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hello all,
I am working on a project that requires the use of .NET remoting, however I am experiencing some strange issues and I wonder if anyone can help me.
I am exposing a preexisting object through the use of RemotingServices.Marshal
After setting up all of the appropriate ChannelServices, I expose the object via:
<br />
RemotingServices.Marshal(ObjName,"RemoteObjName");<br />
This object however has public properties which can be gotten or set. However, when I execute the following code:
<br />
ObjType remInt = (ObjType)Activator.GetObject(typeof(ObjType) ,"tcp://localhost:9555/RemoteObjName");<br />
<br />
remInt.p1 = 15<br />
Console.WriteLine(remInt.p1)<br />
In this case 15 is printed, just as one would expect, however to all other remoting clients and the process that has marshaled the remote object p1 does not change. It maintains the value that it held previously.
If anyone has experienced a similar problem and can provide me any assistance, I would greately appreciate it.
Thanks
|
|
|
|
|
Hi there
I am having problems using the XmlDocument class when editing an xml file.
This is what my xml file looks like :
<VTs_InfoKeeper>
<WebPwds>
<WebPwd>
<website>Code Project</website>
<uid>visiontec</uid>
<pwd>somefakepwd</pwd>
<description>gr8 website. c# fourms and more.</description>
</WebPwd>
</WebPwds>
</VTs_InfoKeeper>
This is the way i am using XmlDocument :
private bool SaveXml( string WebsiteName,
string UserId,
string Pwd,
string Description )
{
XmlDocument doc = new XmlDocument();
try
{
doc.Load("vtinfokeeper.xml");
}
catch(Exception)
{
return false;
}
XmlElement newWebPwd = doc.CreateElement("WebPwd");
XmlElement newWebsite = doc.CreateElement("website");
newWebsite.InnerText = WebsiteName;
newWebPwd.AppendChild(newWebsite);
XmlElement newUID = doc.CreateElement("uid");
newUID.InnerText = UserId;
newWebPwd.AppendChild(newUID);
XmlElement newPwd = doc.CreateElement("pwd");
newPwd.InnerText = Pwd;
newWebPwd.AppendChild(newPwd);
XmlElement newDescr = doc.CreateElement("description");
newDescr.InnerText = Description;
newWebPwd.AppendChild(newDescr);
doc.DocumentElement.AppendChild(newWebPwd);
XmlTextWriter tr = new XmlTextWriter("vtinfokeeper.xml",null);
tr.Formatting = Formatting.Indented;
try
{
doc.WriteContentTo(tr);
}
catch(Exception)
{
return false;
}
tr.Close();
return true;
}
Now when i run the above code i get this result :
<VTs_InfoKeeper>
<WebPwds>
<WebPwd>
<website>Code Project</website>
<uid>visiontec</uid>
<pwd>vtlives</pwd>
<description>gr8 website. c# fourms and more.</description>
</WebPwd>
</WebPwds>
<WebPwd>
<website>somwwebsite</website>
<uid>somewuid</uid>
<pwd>somwpwd</pwd>
<description>somedescr</description>
</WebPwd>
</VTs_InfoKeeper>
Whereas i wish to accomplish the result below :
<VTs_InfoKeeper>
<WebPwds>
<WebPwd>
<website>Code Project</website>
<uid>visiontec</uid>
<pwd>vtlives</pwd>
<description>gr8 website. c# fourms and more.</description>
</WebPwd>
<WebPwd>
<website>somwwebsite</website>
<uid>somewuid</uid>
<pwd>somwpwd</pwd>
<description>somedescr</description>
</WebPwd>
</WebPwds>
</VTs_InfoKeeper>
What am i doing wrong?
Can anyone plz point out the correct way that i should use
the XmlDocument class to get my desired result.
And as u can see that the pwd field is in clear text,
which way of encryption should i use to secure the pwds?
VisionTec
|
|
|
|
|
You loaded the document, then you told the document to create a new node. It doesn't know you want it inside the WebPwds element, so it just adds it to the end of its children (that means it adds it after the WebPwds element).
You need to call "AppendChild" or something similar from the XmlNode you want to add to. You could for instance do something like:
XmlNode webPwdsNode = doc.FirstChild;
webPwds.AppendChild(newPwdNode);
where newPwdNode is an XmlNode you created that contains all of the information you want.
I personally normally load in a document (I usually validate with a schema too when I load stuff in) and create classes based upon what I read (I do this by hand instead of using serialization). When it's time to write it out, I then create a XmlTextWriter and write out the document from scratch.
I, for one, do not think the problem was that the band was down. I think that the problem may have been that there was a Stonehenge monument on the stage that was in danger of being crushed by a dwarf.
-David St. Hubbins
|
|
|
|
|
<br />
using System;<br />
using System.Threading;<br />
<br />
namespace ConsoleApplication<br />
{<br />
class Page<br />
{<br />
private int _page;<br />
<br />
public Page()<br />
{<br />
_page = 0;<br />
}<br />
<br />
public int CurrentPage<br />
{<br />
get<br />
{<br />
lock(this)<br />
{<br />
_page++;<br />
return _page;<br />
}<br />
}<br />
}<br />
}<br />
<br />
class Class1<br />
{<br />
static bool stop = false;<br />
static Page page = new Page();<br />
<br />
[STAThread]<br />
static void Main(string[] args)<br />
{<br />
Thread[] threads = new Thread[5];<br />
<br />
for (int i = 0; i < threads.Length; i++)<br />
{<br />
threads[i] = new Thread(new ThreadStart(ThreadProc));<br />
threads[i].Name = Convert.ToString(i);<br />
threads[i].Start();<br />
}<br />
Console.ReadLine();<br />
}<br />
<br />
static void ThreadProc()<br />
{<br />
int i;<br />
while (!stop)<br />
{<br />
i = page.CurrentPage;<br />
Console.WriteLine("Thread {1}: Current page number: {0}", i, Thread.CurrentThread.Name);<br />
Console.WriteLine("Thread {1}: Downloading page {0}", i, Thread.CurrentThread.Name);<br />
Console.WriteLine("Thread {1}: Processing page {0}", i, Thread.CurrentThread.Name);<br />
if (i == 10) stop = true;<br />
}<br />
}<br />
}<br />
}<br />
Of course instead of the Console.WriteLine statements, there will actually be functions that perform the action.
What I'm worried about is the following: Since each thread is working with the same ThreadProc, isn't this at all going to affect the local variable (integer) i that refers to the page?
When I actually ran this code, I didn't get the statements to execute in order. Is that okay under the code circumstances? Again, what I mean is when one thread is executing, say downloading, it should then start processing the downloaded page. If that doesn't happen, and another thread, instead, starts downloading it's own page, wouldn't that affect the page processing of the first thread? I guess this is just another method of asking the same question: is anything going to happen to the local variable i in between thread calls?
Am I doing the right thing here, or should I use another method to do what I'm trying to do: Download 5 pages at a time. For each downloaded page: process it, and store information. When reaching 100 pages, stop.
Sammy
"A good friend, is like a good book: the inside is better than the cover..."
|
|
|
|
|
The thread proc is the method that's being executed in a separate thread, so no, the local variable i will NOT be affected. It's only when all the threads access a shared resource - like if you declared i as a field in the class that contains the thread proc. In this case, you can simply use the lock keyword against a shared object (typically in this case, you can lock against typeof(MyClass) so that only one thread can access that object at a time:
public class MyClass
{
private int i;
public MyClass()
{
for (int j=0; j<5; j++)
new Thread(new ThreadStart(this.Increment)).Start();
}
private void Increment()
{
lock(this)
i++;
}
}
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hey,
I receive always following error :
{"Could not bind to the new value member.\r\nParameter name: value" }
System.ArgumentException
I don't find the problem in my source. Can someone have a look to it.
I use the property "Omschrijving" for the displaymember and that is not a problem. Why I have a problem with the property Id? I also check the whole array and there are no null-values in Id.
tkx,
Jac
My code :
..
this.Cmb01.DataSource = Codes.Splitsingen.Items;
this.Cmb01.DisplayMember = "Omschrijving";
this.Cmb01.ValueMember = "Id";
..
In an other class :
public class Splitsingen
{
public static Splitsing Jaarlijks = new Splitsing (1,"1",1,12,"Jaarlijks","Annuel","Yearly");
public static Splitsing Halfjaarlijks = new Splitsing (2,"2",2,6,"Halfjaarlijks","Semestriel","6months");
public static Splitsing[] Items = new Splitsing[5]{Jaarlijks,Halfjaarlijks,Trimestrieel,Maandelijks,Eenmalig};
}
public class Splitsing : CodeX
{
public int AantalPeriodesPerJaar;
public int AantalMaandenPerPeriode;
internal Splitsing(int id, string code, int aantalPeriodesPerJaar, int aantalMaandenPerPeriode, string omschrijvingN, string omschrijvingF, string omschrijvingE) : base(id, code, omschrijvingN, omschrijvingF, omschrijvingE)
{
AantalPeriodesPerJaar = aantalPeriodesPerJaar;
AantalMaandenPerPeriode = aantalMaandenPerPeriode;
}
public Splitsing()
{
}
}
public abstract class CodeX
{
public int Id;
private string OmschrijvingN;
public string Code;
public CodeX()
{
}
internal CodeX(int id, string code, string omschrijvingN)
{
Id = id;
Code = code;
OmschrijvingN = omschrijvingN;
}
public string Omschrijving
{
get
{
if (OmgevingParameter.Taal == Talen.Ned)
{
return OmschrijvingN;
}
}
set
{
}
}
}
|
|
|
|
|
Id in your code is not property - it's a field. Data-binding against properties on objects uses the PropertyManager , which binds against properties. Make Id a property and that should work for you.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I am writing a textbox validator control
how would I check to see if the person presses the backspace button and the delete button and then tell windows not to process those messages as I will do it all myself
------------------
I'm naked under my clothes...
|
|
|
|
|
Simple. Just handle the KeyDown event. Check the KeyCode that is passed to you on the KeyEventArgs for Keys.Delete or Keys.Back . If those are set, set Handled to true :
myTextBox.KeyDown += new KeyEventHandler(myTextbox_KeyDown);
private void myTextBox_KeyDown(object sender, KeyEventArgs e)
{
e.Handled = (e.KeyCode == Keys.Back || e.KeyCode == Keys.Delete);
}
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
is it possible to have a managed c++ class that inherits from an unmanaged c++ class? if so, how would i do that?
|
|
|
|
|
|
sorry. i meant c# class that inherits from unmanaged c++. is there a way to accomplish this?
|
|
|
|
|
No. You would have to encapsulate this unmanaged C++ class in a managed class. The easiest way would be to create a mixed mode Managed C++ assembly that encapsulates this in a managed class, then extend that from C#.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Heath Stewart wrote:
easiest way would be to create a mixed mode Managed C++ assembly that encapsulates this in a managed class
ok. can you point me to some info about that?
thanks.
|
|
|
|
|
Um, try the .NET Framework SDK. You did install that with Visual Studio .NET or with the .NET Framework SDK download, did you not?
Specifically, see Managed Extensions for C++ Programming[^] in the VS.NET product documentation.
Most importantly, remember that the managed code has the same access to .NET assemblies (including the base class library) that every other .NET language. That's the whole point of language interoperability.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hey,
I'd like to develop some open source software for the public mainly for gaming. I would like to take mouse input and convert it so that the computer will assume it as a keystoke.
For example on an intellimouse which has 5buttons if the middle mouse button is pressed i would like to fire say a Keystroke p.
The old microsoft software allowed you to do this, the new ones do not, and hence here i am
Atul
|
|
|
|
|
Do a search on hooks (intercepting the mouse input at a system wide low level) and the SendInput call (simulating a keyboard press).
Both of these things are low level and not represented in the framwork classes, so you'll have to do some interop to get this stuff done in C#.
I, for one, do not think the problem was that the band was down. I think that the problem may have been that there was a Stonehenge monument on the stage that was in danger of being crushed by a dwarf.
-David St. Hubbins
|
|
|
|
|
Good Luck!
Perl combines all the worst aspects of C and Lisp: a billion different sublanguages in one monolithic executable. It combines the power of C with the readability of PostScript. -- Jamie Zawinski
|
|
|
|
|
Update:
part of the solution[^]
the answer was under my nose
this is part of the solution just need to stick a gui on and work out how to fire a keyboard event and i'm nearly there
Hopefully all gamers can use this who have 5 button mice and no software
once i'm finished i'll stick the source up on here
|
|
|
|
|
SendInput is the Win32 function you want to use for this. It can be used to simulate keyboard and mouse actually. You'll definitely need to use interop to make the calls from C#.
I've played around with using it to simulate mouse calls, and it's worked fine in other DirectX games (at the time I was trying to do a little macroing in a popular MMORPG).
If you run into any problems, let me know.
I, for one, do not think the problem was that the band was down. I think that the problem may have been that there was a Stonehenge monument on the stage that was in danger of being crushed by a dwarf.
-David St. Hubbins
|
|
|
|
|
as.thakor@ntlworld.com
could i speak to you by email direct ?
it would be greatly appreciated
Thanks
Atul
|
|
|
|
|
Here's a chunk of code I wrote. This class was basically being hosted by remoting (thus the MarshalByRefObject), but it moves the mouse where you want it. It shows how to interop with SendInput (importing the definition and defining a few structures you'll need).
<div style="font-family:Courier New;font-size:10pt;background-color:#FFFFFF" >
<span style="color:#0000FF;">using </span><span style="color:#000000;">System;<br>
</span><span style="color:#0000FF;">using </span><span style="color:#000000;">System.Runtime.InteropServices;<br>
<br>
<br>
[StructLayout(LayoutKind.Explicit, Size=28)]<br>
</span><span style="color:#0000FF;">public struct </span><span style="color:#000000;">Input<br>
{<br>
[FieldOffset (0)]<br>
</span><span style="color:#0000FF;">public uint </span><span style="color:#000000;">type;<br>
[FieldOffset (4)]<br>
</span><span style="color:#0000FF;">public </span><span style="color:#000000;">MouseInput mi;<br>
[FieldOffset (4)]<br>
</span><span style="color:#0000FF;">public </span><span style="color:#000000;">KeyboardInput ki;<br>
[FieldOffset (4)]<br>
</span><span style="color:#0000FF;">public </span><span style="color:#000000;">HardwareInput hi;<br>
<br>
</span><span style="color:#0000FF;">public const uint </span><span style="color:#000000;">INPUT_MOUSE = 0;<br>
</span><span style="color:#0000FF;">public const uint </span><span style="color:#000000;">INPUT_KEYBOARD = 1;<br>
</span><span style="color:#0000FF;">public const uint </span><span style="color:#000000;">INPUT_HARDWARE = 2;<br>
}<br>
<br>
[StructLayout(LayoutKind.Sequential, Size=24)]<br>
</span><span style="color:#0000FF;">public struct </span><span style="color:#000000;">MouseInput<br>
{<br>
</span><span style="color:#0000FF;">public int </span><span style="color:#000000;">dx;<br>
</span><span style="color:#0000FF;">public int </span><span style="color:#000000;">dy;<br>
</span><span style="color:#0000FF;">public uint </span><span style="color:#000000;">mouseData;<br>
</span><span style="color:#0000FF;">public uint </span><span style="color:#000000;">dwFlags;<br>
</span><span style="color:#0000FF;">public uint </span><span style="color:#000000;">time;<br>
</span><span style="color:#0000FF;">public uint </span><span style="color:#000000;">dwExtraInfo;<br>
<br>
</span><span style="color:#0000FF;">public const uint </span><span style="color:#000000;">MOUSEEVENTF_MOVE = 0x0001; </span><span style="color:#008000;"><br>
</span><span style="color:#0000FF;">public const uint </span><span style="color:#000000;">MOUSEEVENTF_LEFTDOWN = 0x0002; </span><span style="color:#008000;"><br>
</span><span style="color:#0000FF;">public const uint </span><span style="color:#000000;">MOUSEEVENTF_LEFTUP = 0x0004; </span><span style="color:#008000;"><br>
</span><span style="color:#0000FF;">public const uint </span><span style="color:#000000;">MOUSEEVENTF_RIGHTDOWN = 0x0008; </span><span style="color:#008000;"><br>
</span><span style="color:#0000FF;">public const uint </span><span style="color:#000000;">MOUSEEVENTF_RIGHTUP = 0x0010; </span><span style="color:#008000;"><br>
</span><span style="color:#0000FF;">public const uint </span><span style="color:#000000;">MOUSEEVENTF_MIDDLEDOWN = 0x0020; </span><span style="color:#008000;"><br>
</span><span style="color:#0000FF;">public const uint </span><span style="color:#000000;">MOUSEEVENTF_MIDDLEUP = 0x0040; </span><span style="color:#008000;"><br>
</span><span style="color:#0000FF;">public const uint </span><span style="color:#000000;">MOUSEEVENTF_XDOWN = 0x0080; </span><span style="color:#008000;"><br>
</span><span style="color:#0000FF;">public const uint </span><span style="color:#000000;">MOUSEEVENTF_XUP = 0x0100; </span><span style="color:#008000;"><br>
</span><span style="color:#0000FF;">public const uint </span><span style="color:#000000;">MOUSEEVENTF_WHEEL = 0x0800; </span><span style="color:#008000;"><br>
</span><span style="color:#0000FF;">public const uint </span><span style="color:#000000;">MOUSEEVENTF_VIRTUALDESK = 0x4000; </span><span style="color:#008000;"><br>
</span><span style="color:#0000FF;">public const uint </span><span style="color:#000000;">MOUSEEVENTF_ABSOLUTE = 0x8000; </span><span style="color:#008000;"><br>
</span><span style="color:#000000;">}<br>
<br>
[StructLayout(LayoutKind.Sequential, Size=24)]<br>
</span><span style="color:#0000FF;">public struct </span><span style="color:#000000;">KeyboardInput<br>
{<br>
</span><span style="color:#0000FF;">public ushort </span><span style="color:#000000;">wVk;<br>
</span><span style="color:#0000FF;">public ushort </span><span style="color:#000000;">wScan;<br>
</span><span style="color:#0000FF;">public uint </span><span style="color:#000000;">dwFlags;<br>
</span><span style="color:#0000FF;">public uint </span><span style="color:#000000;">time;<br>
</span><span style="color:#0000FF;">public uint </span><span style="color:#000000;">dwExtraInfo;<br>
<br>
</span><span style="color:#0000FF;">public const uint </span><span style="color:#000000;">KEYEVENTF_EXTENDEDKEY = 0x0001;<br>
</span><span style="color:#0000FF;">public const uint </span><span style="color:#000000;">KEYEVENTF_KEYUP = 0x0002;<br>
</span><span style="color:#0000FF;">public const uint </span><span style="color:#000000;">KEYEVENTF_UNICODE = 0x0004;<br>
</span><span style="color:#0000FF;">public const uint </span><span style="color:#000000;">KEYEVENTF_SCANCODE = 0x0008;<br>
}<br>
<br>
[StructLayout(LayoutKind.Sequential, Size=24)]<br>
</span><span style="color:#0000FF;">public struct </span><span style="color:#000000;">HardwareInput<br>
{<br>
</span><span style="color:#0000FF;">public uint </span><span style="color:#000000;">uMsg;<br>
</span><span style="color:#0000FF;">public ushort </span><span style="color:#000000;">wParamL;<br>
</span><span style="color:#0000FF;">public ushort </span><span style="color:#000000;">wParamH;<br>
}<br>
<br>
<br>
<br>
</span><span style="color:#0000FF;">namespace </span><span style="color:#000000;">InputSimulation<br>
{<br>
</span><span style="color:#808080;"> </span><span style="color:#808080;"><br>
</span><span style="color:#0000FF;">public class </span><span style="color:#000000;">InputSimulation : MarshalByRefObject<br>
{<br>
<br>
[DllImport("user32.dll")]</span><span style="color:#0000FF;">public static extern uint </span><span style="color:#000000;">SendInput(</span><span style="color:#0000FF;">uint </span><span style="color:#000000;">nInputs, </span><span style="color:#0000FF;">ref </span><span style="color:#000000;">Input inputs, </span><span style="color:#0000FF;">int </span><span style="color:#000000;">sizeofInput);<br>
<br>
</span><span style="color:#0000FF;">public </span><span style="color:#000000;">InputSimulation()<br>
{<br>
}<br>
<br>
</span><span style="color:#0000FF;">public void </span><span style="color:#000000;">MouseMove(</span><span style="color:#0000FF;">ushort </span><span style="color:#000000;">x, </span><span style="color:#0000FF;">ushort </span><span style="color:#000000;">y)<br>
{<br>
Input[] i = {</span><span style="color:#0000FF;">new </span><span style="color:#000000;">Input()};<br>
i[0].type = 0;<br>
i[0].mi.dx = (</span><span style="color:#0000FF;">int</span><span style="color:#000000;">) x;<br>
i[0].mi.dy = (</span><span style="color:#0000FF;">int</span><span style="color:#000000;">) y;<br>
i[0].mi.dwExtraInfo = 0;<br>
i[0].mi.dwFlags = MouseInput.MOUSEEVENTF_ABSOLUTE | MouseInput.MOUSEEVENTF_MOVE | MouseInput.MOUSEEVENTF_VIRTUALDESK;<br>
i[0].mi.mouseData = 0;<br>
i[0].mi.time = 0;<br>
<br>
</span><span style="color:#0000FF;">uint </span><span style="color:#000000;">ret = SendInput(1, </span><span style="color:#0000FF;">ref </span><span style="color:#000000;">i[0], System.Runtime.InteropServices.Marshal.SizeOf(i[0]));<br>
}<br>
<br>
</span><span style="color:#0000FF;">public void </span><span style="color:#000000;">MouseClick()<br>
{<br>
Input[] i = {</span><span style="color:#0000FF;">new </span><span style="color:#000000;">Input(), </span><span style="color:#0000FF;">new </span><span style="color:#000000;">Input()};<br>
<br>
}<br>
}<br>
}<br>
</span>
</div>
I, for one, do not think the problem was that the band was down. I think that the problem may have been that there was a Stonehenge monument on the stage that was in danger of being crushed by a dwarf.
-David St. Hubbins
|
|
|
|
|