|
Ehsan Baghaki wrote: Is there an alternative class in c# for better http functionality?
Response.Redirect or Server.Transfer
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
I add any zedgraphcontrol to form and i Want with chenge cursor on the right border control and drag , chenge size zedgraphcontrol? pleas help me thanks.
|
|
|
|
|
I have never heard of the zedgrapg control - but why not try putting it on a splitcontainer, docked to fill, then resizing the split container will probably just work as if by magic
___________________________________________
.\\axxx
(That's an 'M')
|
|
|
|
|
I have a typical problem. It is like I want to execute some API calls based on the Platform, if one API is not supported by the current platform it will throw an exception. I want to implement it like this:
<br />
[Platform(Platform.Win32NT)]<br />
[DllImport("somedll.dll")]<br />
public static extern int APIcall([In] int param1, float param2);<br />
<br />
<br />
public int CallTheAPI(int param1, float param2)<br />
{<br />
return APICall(parma1, param2);
}<br />
How should I implement Platform attribute and accomplish the operation? Please give some idea.
|
|
|
|
|
try this one.
<br />
[Platform(Platform.Win32NT)]<br />
[DllImport("somedll.dll")]<br />
public static extern int APIcall([In] int param1, float param2);<br />
<br />
<br />
public int CallTheAPI(int param1, float param2)<br />
{<br />
if (!System.Environment.OSVersion.Platform.ToString().Equals("Win32NT"))<br />
{<br />
throw new ApplicationException("Your current platform is not a Win32NT operating system.");<br />
}<br />
return APICall(parma1, param2);
}<br />
<br />
<br />
|
|
|
|
|
Basically , this is ok for one or two api calls. But I am here handling with more than 300 calls. So instead of putting the if conditions everywhere , just using attribute over each api signature would be lot easier. That is why i am posting this question to get it in a easier way.
|
|
|
|
|
I guess you're looking for a generic method dispatch mechanism that validates the platform before executing calls. How about something like this.
enum Platform
{
XP,
NT,
Vista
}
class PlatformNameAttribute : Attribute
{
public PlatformNameAttribute(Platform platForm)
{
this.Platform = platForm;
}
public Platform Platform { get; set; }
}
class Program
{
[PlatformName(Platform.NT)]
static void SomeAPICall()
{
Console.WriteLine("NT");
}
[PlatformName(Platform.XP)]
static void SomeOtherAPICall(int x)
{
Console.WriteLine("XP");
}
static Platform GetCurrentPlatform() { return Platform.NT; }
static void ExecuteAPICall(Delegate d, params object[] parameters)
{
var attributes = d.Method.GetCustomAttributes(typeof(PlatformNameAttribute), false);
if (attributes != null && attributes.Count() > 0)
{
var platformAttribute = (PlatformNameAttribute)attributes[0];
if (platformAttribute.Platform != GetCurrentPlatform())
{
throw new InvalidOperationException("Platform Type mismatch");
}
d.DynamicInvoke(parameters);
}
}
static void Main(string[] args)
{
ExecuteAPICall(new Action(SomeAPICall));
ExecuteAPICall(new Action<int>(SomeOtherAPICall), 2);
}
You could do something more typesafe than DynamicInvoke, with Expression and lambdas, but that would require .NET 3.5, and I'm not sure you are running it.
|
|
|
|
|
That's a cool solution and I already tried it. But the problem is when API calls uses parameters with ref / out keyword or it has a large number of parameters say 7 or something or have parameters with marshalas attributes you can't use either Action or Func. I am not sure in that case if this method dispatcher will work or not.
For your information I am using .Net 3.5.
Any kind of suggestion is highly required.
Thanks.
|
|
|
|
|
I have the class Class1:
public enum Protocol
{
Digital,
Analog
}
public enum Model
{
Digital1,
Digital2,
Analog1,
Analog2
}
public static Protocol m_selectedProtocol;
public static Model m_ModelSelected;
public static Protocol SelectedProtocol
{
get { return Class1.m_selectedProtocol; }
set { Class1.m_selectedProtocol = value; }
}
public static Model ModelSelected
{
get { return Class1.m_m_ModelSelected ; }
set { Class1.m_ModelSelected= value; }
}
Then here is the code being executed:
if (rdAnalog.Checked == true)
{
Class1.SelectedProtocol = Protocol.Analog;
if (Analog1.Checked == true)
{
Class1.ModelSelected = Model.Analog1;
}
else if (Analog2.Checked == true)
{
Class1.ModelSelected = Model.Analog2;
}
else
{
return;
}
else
{
return;
}
i have this error when this line is executed :Class1.SelectedProtocol = Protocol.Analog;
How can it be solved ? thanks
|
|
|
|
|
The code you have presented (except of a coouple of typos) works -
public class Class1
{
public enum Protocol
{
Digital,
Analog
}
public enum Model
{
Digital1,
Digital2,
Analog1,
Analog2
}
public static Protocol m_selectedProtocol;
public static Model m_ModelSelected;
public static Protocol SelectedProtocol
{
get { return Class1.m_selectedProtocol; }
set { Class1.m_selectedProtocol = value; }
}
public static Model ModelSelected
{
get { return Class1.m_ModelSelected ; }
set { Class1.m_ModelSelected= value; }
}
}
private void button1_Click(object sender, EventArgs e)
{
Class1.SelectedProtocol = Class1.Protocol.Analog;
}
so there is something in the code you have not posted causing the problem - are you able to post some complete code that shows the problem?
___________________________________________
.\\axxx
(That's an 'M')
|
|
|
|
|
Here is the code :
if (rdAnalog.Checked == true)
{
Class1.SelectedProtocol = Protocol.Analog;
private void buttonStartTest_Click(object sender, EventArgs e)
{
try
{
if (Analog1.Checked == true)
{
Class1.ModelSelected = Model.Analog1;
}
else if (Analog2.Checked == true)
{
Class1.ModelSelected = Model.Analog2;
}
else
{
return;
}
else
{
return;
}
}
catch (Exception c)
{
MessageBox.Show(c.Message);
Environment.Exit(0);
}
}
|
|
|
|
|
I'd need to see the code for Class1 - sorry if I wasn't clear. As someone says below, it could be a static constructor causing the issue - but without seeing the code for the class it's hard to guess.
___________________________________________
.\\axxx
(That's an 'M')
|
|
|
|
|
It seems that you have missed a '}' in your code. Changing your code like below is working
if (rdAnalog.Checked == true)
{
Class1.SelectedProtocol = Protocol.Analog;
if (Analog1.Checked == true)
{
Class1.ModelSelected = Model.Analog1;
}
else if (Analog2.Checked == true)
{
Class1.ModelSelected = Model.Analog2;
}
else
{
return;
}
}
else
{
return;
}
|
|
|
|
|
One of the types involved probably has a static constructor, and I'm guessing that static constructor is throwing an exception.
Put breakpoints in the static constructors of all classes involved, and step through them in the debugger.
|
|
|
|
|
hello
I installed my keypair into CSP using sn.exe
sn.exe -i mykeypair.snk MYKEYPAIR_RSA_SNKContainer
Now how do I access CSP? I can't find anything under Control Panel>Administrative tools.
Thanks
dev
|
|
|
|
|
Hi,
while working with an application , i came across method signature that used 'this' keyword. I googled alot but coudn't find any article that provided help, would anybody over here please tell me or either forwrd me an article that explains this method description. thankou
public static bool IsPart(this Product product)
{
try
{
return product.isPart.Value == "true" ? true : false;
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
return false;
}
}
though, i have pasted the whole method but i am confused with function signature . Thanx for providing help
|
|
|
|
|
Hi,
yes that syntax is a bit strange, google for "C# extension methods", a recent C# feature.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
|
you're welcome.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Good people,
How do I use the preprocessor "#if" to detect whether my app is running in debug or release mode?
(I know, I'm embarrassed to ask. Here, I've built an entire app and don't know how to detect debug mode. Doh!)
Thanks,
Blitz
|
|
|
|
|
Hi,
by default a debug build has DEBUG and TRACE predefined, whereas a release build has not.
However you can change these settings (and predefine other symbols) in the build tab of the project properties.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
#if DEBUG
code goes here
#endif
easy as that!
___________________________________________
.\\axxx
(That's an 'M')
|
|
|
|
|
Thank you all so much. I appreciate it.
|
|
|
|
|
Hi, In my application i need to open 2 forms. After the first form is loaded, iti loads a second form with the following..
System.Threading.Thread MainFormThread = new System.Threading.Thread(new System.Threading.ThreadStart(OpenMainForm));
MainFormThread.Start();
System.Threading.Thread.Sleep(1500);
Where OpenMainForm() just has Application.Run(new MainForm());
The MainForm has a webbrowser control, and it will not compile due to the error:
ActiveX control '8856f961-340a-11d0-a96b-00c04fd705a2' cannot be instantiated because the current thread is not in a single-threaded apartment.
Does anyone know how i can solve this issue?
Thanks for reading.
Andy
|
|
|
|
|
The Web Browser control is designed to run in a Single threaded fashion.
You can not use multi threading when using Web Broswer Control.
BTW, why do you need a seperate thread for this? You can use a timer instead.
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|