|
I SERIOUSY DOUBT you're getting 1,000 frames per second nor even have the hardware that can do it. There's just no point to it because the human eye just can't see that. Knock that back to AT MOST 60 frames a second and you might improve your situation dramatically.
|
|
|
|
|
I miss discribed my situation. I dont have over 1000 Frames, my update & Draw Thread are called more then 1000 Times. But that doesn't mean it is really the Render Thread of DirectX.
So now with ur conclusion of slowing it down to 60 fps the gui is now responsive again. Easy Solution.
Side way i still ask if someone knows a way to store properties out of the WPF Thread?
|
|
|
|
|
Hi Folks,
I have a question about the best way to design / redesign my software. I have a program that uses a web services to perform certain tasks. Each task is a different set of request / response classes on the server end and a general function call from the Main Hook. EG.
RequestObject req = new RequestObject("SomeVal");
ResponseObject rsp = new ResponseObject();
rsp = WebServiceHook.Method1(RequestObject);
Each Method takes a different request object and returns a different type of response object.
As it stands i have a class for each of these methods, Each class has a public method Process() that does the interaction. I am trying to determine the best way to group all this code together using OO techniques without sacrificing functionality. I would like just one ProcessMethod in one class that will handle the interaction with the webservice for all the different web methods. So i would only call one ProcessMethod passing a switch of sorts that would define the relevant types and uniques strings that method requires. Some Sample code below:
[ComVisible(false)]
private static InfoRequest infoReq = null;
[ComVisible(false)]
private static InfoResponse infoRsp = null;
public static bool Process(INTERFACEREQUEST COMReq, out INTERFACERESPONSE COMRsp)
{
bool blnReturnVal = false;
CInfoRsp InfoRsp = new CInfoRsp();
CInfoReq InfoReq = (CInfoReq)COMReq;
Globals.dtStart = DateTime.Now;
Globals.Log(Logger.LogLevel.Minimum, Logger.LogType.APIMethodEntryPoint, "SOME TEXT HERE", "AND HERE", InfoReq.SalePointID);
try
{
Globals.TheService.Url = Settings.URL;
infoReq = new InfoRequest();
infoRsp = new InfoResponse();
SetRequest(InfoReq);
CallWEBServiceMethod();
SetCOMResponseValues(InfoRsp);
COMRsp = InfoRsp;
blnReturnVal = AssignCOMResponse(InfoRsp);
}
catch (Exception ee)
{
COMRsp = new CInfoRsp(ee);
blnReturnVal = false;
Globals.Log(Logger.LogLevel.All, Logger.LogType.APIMethodException, ee.ToString() + " " + ee.InnerException);
}
finally
{
InfoRsp = null;
InfoReq = null;
infoReq = null;
infoRsp = null;
GC.Collect();
}
}
Is what i am trying to achieve possible or am i trying to over engineer this solution. It currently works i just find every time i have to add a new web method call i clone one of the existing classes and change the types in the processMethod and anywhere else that's needed. This is quite tedious and prone to bugs.
Thanks In Advance
|
|
|
|
|
|
KeithF wrote: Am i correct in saying this?
Yes.
You'd want an (abstract) base-class that defines the Process method;
public abstract bool Process(BaseProcessArgs args)
{ The factory would return a class that derives from this abstract base-class, with each class having it's own implementation for the Process method. The app would only have to call the method, without knowing specific details on the class.
Varying the parameters can be done in a similar way; EventArgs is a nice example on how to vary parameters, and still have some control. Imagine a base-class for the arguments, called "BaseProcessArgs"; if you'd need to pass a string and an int, your "Args" class would look like below;
class TestArgs: BaseProcessArgs
{
public string TestString { get; set; }
public int TestInt { get; set; }
} Alternatively, if only types will change, you might want to consider a generic class.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Folks,
Question about my design so far, I am wondering if i am going about this the right way?
I have a COM Library created in C#, with COMVisible set to true. This library talks to a 3rd party WebService calling various methods depending on the task at hand. For each Request / Response class exposed by the 3rd party DLL I have a Request / Response Pair (Class and Interface) to Marshal variables specifically for a VC6 application.
Mainly using:
MarshalAs(UnmanagedType.LPStr)]
So with that in my i have added a C# project to the solution to test this code, see test method below:
static void Main(string[] args)
{
ICOMReq iReq = new CCOMReq();
ICOMRsp iRsp = new CCOMRsp();
Link l = new Link();
iReq.Date_Time = DateTime.UtcNow;
iReq.Var2 = "1023758145865";
l.DoMethod1(iReq, out iRsp);
}
The link class looks like so at the moment be but will have all the methods created once the design is correct:
public class Link
{
public bool DoMethod1(ICOMReq _COMReq, out ICOMRsp COMRsp)
{
Method1 WebServiceMethod = new Method1(new Method1Request(), new Method1Response(), (CCOMReq)_COMReq, new CCOMRsp());
WebServiceMethod.Process();
COMRsp = null;
return true;
}
}
Each DoMethod(N) that will be in the link class will look the same performing its task with identical code to the other DoMethods. The key differences between the methods is the Param Types Passed in and the Method1 (Method1Request/Method1Response) type will vary depending on the webmethod to be called.
Class Method1 (There will be one of these for every method I need to implement on the WebService) looks like so:
public class Method1 : WebServiceInterfaceBridge<Method1Request, Method1Response, ICOMReq, ICOMRsp>
{
public Method1(Method1Request WEB_Req, Method1Response WEB_Rsp, CCOMReq COM_Req, ICOMRsp COM_Rsp)
: base(WEB_Req, WEB_Rsp, CBE_Req, CBE_Rsp)
{
WEB_Req.SOME_DATE_TIME = COM_Req.Date_Time;
}
public new void Process()
{
base.Process();
}
public override void LOG()
{
Console.WriteLine(this.WebMethod_Request.MEMBER_VAR_HERE);
}
}
The class (WebServiceInterfaceBridge) that all Method(N) classes will inherit from is shown below:
public abstract class WebServiceInterfaceBridge <T,U,V,W> : WebServiceInterface
where T : class
where U : class
where V : class
where W : class
{
protected T WebMethod_Request;
protected U WebMethod_Response;
protected V COM_Request;
protected W COM_Response;
public WebServiceInterfaceBridge(T tPHSReq, U uPHSRsp, V vCBEReq, W wCBERsp)
{
WebMethod_Request = tPHSReq;
WebMethod_Response = uPHSRsp;
COM_Request = vCBEReq;
COM_Response = wCBERsp;
}
public abstract void LOG();
public void CallWebServiceMethod()
{
WebMethod_Response = CallWebMethod<T, U>(WebMethod_Request);
}
public void Process()
{
LOG();
CallWebServiceMethod();
}
}
And finally here is the class that actually calls the Web service that the WebServiceBridge Class inherits from:
public class WebServiceInterface
{
private ServiceClient WEBSVC = new ServiceClient();
public U CallWebMethod<T, U>(T tRequest)
where T:class
where U:class
{
if (tRequest.GetType() == typeof(Method2Request))
{
Method2Request Req = (Method2Request)(object)tRequest;
Method2Response Rsp = WEBSVC.Method2(Req);
return (U)(object)Rsp;
}
else if (tRequest.GetType() == typeof(Method1Request))
{
Method1Request Req = (Method1Request)(object)tRequest;
Method1Response Rsp = WEBSVC.Method1(Req);
return (U)(object)Rsp;
}
else
{
throw new NullReferenceException();
}
}
}
I have left out my internal classes for marshaling the Req/Rsp's, they are just classes with Member Vars and Get/Set's.
So basically before i carry on with my design I am wondering from an OO point of view if I am approaching this task in the right way or if what I am doing is overkill and could be greatly simplified?
TIA
|
|
|
|
|
Hi All,
I have used this sample as reference How to use a web cam in C# with .NET Framework 4.0 and Microsoft Expression Encoder 4[^]
and managed to modify the files to stream to my IIS . I have no issue streaming towards my own IP address . However , problem arises when i try to stream it to another IP address . It disconnected after few minutes of streaming but strangely at times it works fine(Not most of the time) . Asked at Microsoft Expression Encoder Forum and no one dares to answer me . I hope here are brave programmers here which can help me solve this particular issue . Do request me if you need to take a look at my codes .
Thanks ,
Daniel
|
|
|
|
|
What does this have to do with C#?? A dropped connection doesn't have anything to do with your code. Once the connection starts it's up to Encoder and the client to keep it going. Your code has nothing to do with it.
|
|
|
|
|
I want to get the caret position with my C# application.but in some cases ,GetGuiThreadInfo does not work creectly.
it works well on
1. notepad
2. ie
3. explorer
4. word
and works bad on (hwndCaret will be 0)
1. Visual Studio
2. Firefox
3. Sublime Text 2
Anyone who can helps me?
public partial class Form1 : Form
{
[DllImport("user32.dll")]
public static extern IntPtr GetForegroundWindow();
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
[DllImport("user32.dll")]
static extern uint GetWindowThreadProcessId(IntPtr hWnd, IntPtr ProcessId);
[DllImport("user32.dll")]
static extern bool GetGUIThreadInfo(uint idThread, ref GUITHREADINFO lpgui);
[StructLayout(LayoutKind.Sequential)]
public struct GUITHREADINFO
{
public int cbSize;
public int flags;
public IntPtr hwndActive;
public IntPtr hwndFocus;
public IntPtr hwndCapture;
public IntPtr hwndMenuOwner;
public IntPtr hwndMoveSize;
public IntPtr hwndCaret;
public Rectangle rectCaret;
}
public GUITHREADINFO? GetGuiThreadInfo(IntPtr hwnd)
{
if (hwnd != IntPtr.Zero)
{
uint threadId = GetWindowThreadProcessId(hwnd, IntPtr.Zero);
GUITHREADINFO guiThreadInfo = new GUITHREADINFO();
guiThreadInfo.cbSize = Marshal.SizeOf(guiThreadInfo);
if (GetGUIThreadInfo(threadId, ref guiThreadInfo) == false)
return null;
return guiThreadInfo;
}
return null;
}
public void SendText(string text)
{
IntPtr hwnd = GetForegroundWindow();
if (String.IsNullOrEmpty(text))
return;
GUITHREADINFO? guiInfo = GetGuiThreadInfo(hwnd);
AddMessage("go");
if (guiInfo != null)
{
IntPtr ptr = (IntPtr)guiInfo.Value.hwndCaret;
AddMessage("hwndCaret = " + ptr.ToInt32());
if (ptr != IntPtr.Zero)
{
AddMessage("Left = " + guiInfo.Value.rectCaret.Left);
for (int i = 0; i < text.Length; i++)
{
SendMessage(ptr, 0x102, (IntPtr)(int)text[i], IntPtr.Zero);
}
}
}
}
public Form1()
{
InitializeComponent();
}
private void AddMessage(string message)
{
var i = listBox1.Items.Add(message);
listBox1.SelectedIndex = i;
}
private void button1_Click(object sender, EventArgs e)
{
Thread.Sleep(2000);
SendText("Abcdefg");
AddMessage("------------");
}
}
|
|
|
|
|
hey Friends....
I have a Table with Name (Student_Table)
fields(Stdid, StdRollNo, StuName)
with 5 records
And A windows Form With Name Form1
Now, My question is..
I want Dynamic Buttons equals to students records ie.. 5 buttons,
on That Buttons i want Student Roll No.
please guys help me
Jack_Spero
|
|
|
|
|
your question has been answered in the other forum you asked it in - a friendly bit of advice - please dont cross post - pick the best forum, post the question once !
'g'
|
|
|
|
|
Hello
I have been trying to export a string array from my C# unmanged DLL export to metatrader , but can not do that , please need you expert suggestion ..
[DllExport("_CheckStringArray", CallingConvention = CallingConvention.StdCall)]
public static void _CheckStringArray([In, Out, MarshalAs(UnmanagedType.LPStr)] StringBuilder [] str)
{
try
{
str[0].Append("hello");
}
catch (Exception e)
{
MessageBox.Show(e.ToString());
}
}
#import "CyboMySqlRead.dll"
void _CheckStringArray(string s[]);
string array [3] ;
_CheckStringArray(array)
Print(array[0]);
|
|
|
|
|
Is there a shorthand for updating an object? Something like an initializer?
var item = new FooViewModel { id = "test", name = "test" };
Something like that but instead:
Record myRecord = Context.RecordRepository.GetById(1234);
myRecord {
id = 123,
name = "blah"
}
Cheers, --EA
|
|
|
|
|
|
The best you can do is try and using LINQ to fetch and update records in the same line.
However, what you are tyring to do is not directly possible.
|
|
|
|
|
In VB.net its called "WITH"
C# dont have this trick... But, you can use this:
public static void With<T>(this T _object, Action<T> _action)
{
_action(_object);
}
Usage:
LongInstanceOfPersonVariableName.With(x => {
x.AgeIntVar = 21;
x.NameStrVar = "John";
x.NameStrVar += " Smith";
});
from http://stackoverflow.com/a/5964848[^]
I dont think its the best solution... But... It may work.
modified 24-Jul-13 7:36am.
|
|
|
|
|
I have C# MDI Form EXE as a framework. In which I have to deployed my VB 6 OCX, and also calls another VB 6 OCX from displayed OCX events.
Is this possbile? where I have to make changes C# or VB 6.0?
Does anyone has made similar kind of project before?
Any link?
Thanks in Advance
|
|
|
|
|
It's just a COM component. You just add a reference to it and use it like any other class.
|
|
|
|
|
Thanks Dave,
fisrt COM component loaded fine in C#.net exe framework. My problem is to load another COM component into same C#.net exe framework, and this second COM component will be called from first COM component.
Hope you understand my problem.
Any idea?
|
|
|
|
|
Exactly the same as before. You add a reference to it.
You're problem is that your COM componets should not be calling into each other. That would be a hard-code tie where you couldn't use one component without the other. That's just a bad design.
|
|
|
|
|
I need to use a generic collection of keyvalue pair. I need thr folloeing:
1) should be generic because my values are a customized class
2) iterating should keep the order in which I added Items
3) I should be able to find the index of the element
4) I need access via Key
A dictionary is ok for 1,2,4 but not for 3
SortedList and SortedDictionary are ok for 1, 3, 4 but not for 2.
If I create a
List<keyvaluepair> it is ok for 1,2,3 but not for 4 ( I mean not directly)
SortedList<string, double> d = new SortedList<string, double>();
d.Add("z", 1);
d.Add("a", 2);
d.Add("c", 3);
d.Add("b", 4);
foreach (KeyValuePair<string,double> k in d)
{
Console.WriteLine(k.Key + " " + k.Value);
}
KeyValuePair<string, double> i_item = d.ElementAt(2);
Any suggestion?
Thanks for your time
|
|
|
|
|
If I change your code to use a Dictionary it works for me...
If you directly want to access a value you can also do this:
var value = d["c"];
whil returns the value 3 in this case.
What error do you get when using the Dictionary class?
|
|
|
|
|
KeyValuePair<string, double> i_item = d.ElementAt(2);
may be I was not clear I can't get item from index value. For example I need the second element How can I ask the Dictionary the second element?
The dictionary is an unsorted collection
|
|
|
|
|
An unsorted collection is what you're looking for if you want to prevent the order in which the items were added.
And I don't know what error you're getting when calling
KeyValuePair<string, double> i_item = d.ElementAt(2);
as this works just fine for me with a dictionary
|
|
|
|
|
thanks you are right sorry. Basically I need to find the index from the key and viceversa.
How can I find the index related to the key "3", from the dictionary. It should be 2
|
|
|
|