|
Thanks for the quick answer!
I'm still a little confused, though. It looks like you are specifying a type of handler, and not a specific instance of a handler?
In other words, did I write a handler somewhere, that is being called when B.CheckStateChanged fires for B?
And what did it look like (the declaration)?
Thanks!
|
|
|
|
|
I am sorry, I shouldnt have used the Event name
B.CheckStateChanged += new System.EventHandler(CheckStateChanged_Event);<br />
<br />
void CheckStateChanged_Event(object sender, System.EventArgs e)<br />
{<br />
}
I guess this makes it clearer
Tarakeshwar Reddy
MCP, CCIE Q(R&S)
|
|
|
|
|
I think I'm starting to get it. I posted a more generalized question over in C# based on this.
My question really deals with writing handlers when you can't know the name of the object ahead of time, as when you create arbitrary controls like above.
I think you may have answered it. If B supports a CheckStateChanged property, and it changes, then the CheckStateChanged_Event handler will fire, and I'll be able to look at the Sender to see which item changed, and look at the sender.CheckState to see what the new state is?
Again, thanks for helping me past my ignorance. The .NET framework is fairly new to me. As is C#, sort of. Seriously, I rely way too much on Intellisense to let me know what's available...
|
|
|
|
|
JoeRip wrote: I'll be able to look at the Sender to see which item changed, and look at the sender.CheckState to see what the new state is?
You could use the Text or the Name property to identify the sender and accordingly write a switch block or an if condition.
((ToolStripMenuItem)sender).Text;<br />
((ToolStripMenuItem)sender).CheckState
JoeRip wrote: Again, thanks for helping me past my ignorance. The .NET framework is fairly new to me. As is C#, sort of.
Just have a look at the articles available on this site, you can gain tremendous amount of knowledge.
Tarakeshwar Reddy
MCP, CCIE Q(R&S)
|
|
|
|
|
Consider the following:
namespace Lesson2
{
class Program
{
static void Main(string[] args)
{
System.Threading.ThreadStart oThreadStart;
oThreadStart = new System.Threading.ThreadStart(UpdateCount);
System.Threading.Thread[] oThreads;
oThreads = new System.Threading.Thread[10];
for (int i = 0; i < oThreads.Length; i++)
{
oThreads[i] = new System.Threading.Thread(oThreadStart);
oThreads[i].Start();
}
// Wait for them to complete
for (int i = 0; i < oThreads.Length; i++)
{
/*
* The different threads in 'oThreads' use the same
* variable 'Counter.Count'.
* => The variable 'Counter.Count' is shared by these threads.
*
* Without 'Join' the 'WriteLine' does his work before the
* last thread is done.
* => Total is less then 100.000.
*/
oThreads[i].Join();
}
/*
* Show to the console the total value of 'Counter.Count'
*(after the 10 threads)
* Should be 10 * 10.000 = 100.000
*/
Console.WriteLine("Total: {0}", Counter.Count);
Console.ReadLine();
}
static void UpdateCount()
{
for (int i = 1; i <= 10000; ++i)
{
Counter.Count = Counter.Count + 1;
}
}
}
public class Counter
{
public static int Count;
}
}
The expected 'Total' that is written to the console is '100.000' (10 threads that increment 'Counter.Count' with '10.000').
The book i'm currently reading
(http://www.amazon.com/MCTS-Self-Paced-Training-Exam-70-536/dp/0735622779)
says that if you run this code on a hyperthreading- or a multiprocessorsystem
the 'Total' that is written to the console will sometimes be less than '100.000'. I don't understand the explanation.
|
|
|
|
|
The potential problem on a hyperthreaded or multi-processor PC is due to the fact that each processor in a PC maintains its own cache. Therefore, if any of the threads executing in your routine happen to run on a different processor, that processor updates its own cache and does not automatically publish the new value to the other processor. This would cause your counter to 'miss' that particular iteration of the counter.
There are several potential solutions to get around this, for instance using the VolatileRead and VolatileWrite methods of the Thread class (these use shared memory that all processor's can access, rather than storing the value of your variable in a CPU register) or using the MemoryBarrier of the Thread class (this method flushes the caches and CPU registers of all the processors into memory, ensuring that variables contain current data). You can get plenty of info on the Thread class and it's methods on the MSDN website.
Hope that helps.
|
|
|
|
|
|
hi , i use from from Shockwave Flash Component in visual studio 2003 without any problem but in VS 2005 whene i want add Shockwave Flash Component to a form,VS2005 show a Error and say i should register "Shockwave Flash Component". please help me.
|
|
|
|
|
How can I get a reference of the calling Assembly at Runtime?
I've an assembly (RestrictedAssembly) and I want to ristrict access to it means no user who
fullfills my criteria (in my case not having my desired public key token for assembly) can
instantiate any type from my assembly.
For better understanding, this is what I am trying to do.
I've generated a public/private keypair file for myself, then I use it to sign all those assemblies
which I want to allow Access to my RestrictedAssembly. On Runtime before instantiating any type from
RestrictedAssembly, in constructor I am asking the caller to provide a Type object from which he's
initiating a call to constructor. For example.
public RestrictedType1(Type o) {
Type t = this.GetType ();
byte [] t1Token = o.Assembly.GetName().GetPublicKeyToken();
byte [] t2Token = t.Assembly.GetName().GetPublicKeyToken();
AccessNotAllowedEx ex = new AccessNotAllowedEx("Not Allowed");
if(t1Token != null && t2Token != null) {
if(t1Token.Length == t2Token.Length) {
for(int i = 0; i< t1Token.Length; i++) {
if (t1Token[i] == t2Token[i])
continue;
else
throw ex;
}
ex = null;
} else
throw ex;
} else
throw ex;
}
I am checking, if the public key tokens for both the calling and called assemblies are identical and
if they are, then I am allowing the caller to instantiate my RestrictedType other wise I raise an
exception.
Now the problem with this approach is that, suppose I've an Assembly CallerOfRestrictedAssembly and
I've signed it with my public/private key pair. Now from CallerOfRestrictedAssembly it is valid to
do the following. Since both assemblies have same public key token.
RestrictedType1 res = new RestrictedType1(this.GetType);
However, suppose if some one initiate a call to RestrictedType1 constructor
RestrictedType1 res = new RestrictedType1(typeof(TypeFromCallerOfRestrictedAssembly));
This will cheat the constructor. Thus, I don't want caller to Pass Type argument into Constructor.
and depend on it. What I am looking for is to get a reference of Calling Assembly into my
RestrictedAssembly at Runtime?
I'll apreciate if some can help with this or any other approach to achieve this level of code
restriction? Thanks.
SMK
|
|
|
|
|
Please don't cross post.
---
It's amazing to see how much work some people will go through just to avoid a little bit of work.
|
|
|
|
|
Can anybody help me to understand and use 'ExecutionContext'
(or give me za good link)
|
|
|
|
|
I am curious as to what would be the best method to determine the memory allocation footprint of a filled dataset object.
Can anyone point me in the right direction?
|
|
|
|
|
I got this question in a tech interview,
tell me any one ARCHITECTURAL DIFFERENCE between .net 1.0 and 2.0?
can you guys list out a few please??
|
|
|
|
|
karam chandra bose wrote: ARCHITECTURAL DIFFERENCE between .net 1.0 and 2.0
Here is from wiki... http://en.wikipedia.org/wiki/.NET_Framework[^]
If you try to write that in English, I might be able to understand more than a fraction of it. - Guffa
|
|
|
|
|
Well, there's generics and nullable datatypes for a start.
the last thing I want to see is some pasty-faced geek with skin so pale that it's almost translucent trying to bump parts with a partner - John Simmons / outlaw programmer
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Hi all,
What is the best pratice / methods / or technologie to be used to create a GUI interface that will be connected to a windows service written in .NET/C#.
I need to display buttons that will trigger some actions on the service, a listbox-like controle that will trace log from work done on the service and so on...
Do you have any idee on how to do this ?
Thanks
|
|
|
|
|
Well, I have a control I use for viewing the states of services which has buttons for Start and Stop.
You can add custom actions to a service, but I don't know if you can get data back from a service directly. Or maybe use remoting?
The best I have is a service that creates an XML file that another application uses.
|
|
|
|
|
Hi PIEBALDconsult,
In fact I want to remotely start a Form hosted by the service.
The Form will have Button, Checkbox and Log-list that would permit to change the behavior of the service. For example: change the trace level, call a special methode, set/change some values...
You are right, I could use Remoting with a interface. But I don't want to change the interface, for example every time I add a new button to the form.
Rather than calling a Method, I need to instanciate a assembly remotely or
in other words, I need a little VNC functionality on a Form.
Does anyone has an Idea ?
Christophe
|
|
|
|
|
Hi,
I am unable to edit my Data grid. I also wants to change my width of edited text box.
Thanks & Best Regards
Manvendra Kushwaha
Software Developper
|
|
|
|
|
hi ,
goto datagrid property builder and add bound colums . each bound colum heder text,databoundcolum . type name in the header text colum and type database field name in the data field . after convert into template colum . and write this code to edit the textbox
//inside event
Edit_Click
{
DataGrid1.EditItemIndex=e.Item.ItemIndex;
Bind();
}
Bind Method is for Bind the data to datagrid Common code
right click the datagrid and go to edit template column there u wil l find the text box and gotot properties and change width
i thnk htis will help u.
thanks and regards
kinnu
kinnu
|
|
|
|
|
Hi!
I don't know if I'm missing something in System.Configuration namespace (.NET 2.0), but I just don't know how to use external .config file (other than machine.config, web.config or app.config).
Before, when Configuration Block was part of Enterprise Library, either web.config or app.config (depending on type of application) could have defined section for Enterprise Library which contained path to external .config file and class (full name) which represented some kind of configuration manager for that configuration.
Now, configuration is not part of the Enterprise Library anymore, and it seems like everything should be part of single .config file.
I hope I explained my problem clearly.
Thanks.
|
|
|
|
|
Hi
When I type turkish letters(Ğİö..) in a text box and try to pull data, it returns no row..
But when I type select command to SQL Enterprise manager and try to pull same data, it works...
My SQL command is "select * from myTable where (column1='Ğİ' COLLATE Turkish_CI_AI)
I make,
System.Threading.Thread.CurrentThread.CurrentCulture= new System.Globalization.CultureInfo("tr-TR");
in program init...
I put Language setting to form and Localizable=true
This problem only occurs on windows 2000 english, I have no problem with windows XP turkish
I hope I could explain my problem...
Thanks
|
|
|
|
|
I've been converting / writing a handful of apps using Visual Studio 2005 and publishing the files for ClickOnce upgrades.
When we wrote applications with VS2003 we setup app-config files and could change parameters in our apps by adjusting the app-config without recompiling.
Now with ClickOnce we publish to a location on our intranet and install the app on each local workstation. Where is the app-config. It seems like we now have to change the app-config in Visual Studio and re-publish. There should be a way to just go to the app-config at some central location to change parameters if needed?
I'm missing some piece of knowledge that hopefully somebody has.
Thanks for any help
Lost in the vast sea of .NET
|
|
|
|
|
Hey!
I am building on a simple chat application that uses callbacks. The contract are created in a class library that are then referd to in myWCFCallBackHost, the contract looks like this:
Contract:
<br />
namespace myWCFCallBackService<br />
{<br />
[ServiceContract(SessionMode=SessionMode.Required, CallbackContract = typeof(IChangedHandler))]<br />
public interface IChat<br />
{<br />
[OperationContract(IsOneWay=false, IsInitiating = true)]<br />
void Subscribe(string inName);<br />
<br />
[OperationContract(IsOneWay = false, IsTerminating = true)]<br />
void Unsubscribe();<br />
<br />
[OperationContract(IsOneWay = true)]<br />
void publishNewMessage(string inMessage, string inName);<br />
}<br />
<br />
public interface IChangedHandler<br />
{<br />
[OperationContract(IsOneWay = true)]<br />
void changed(string newMessage);<br />
}<br />
<br />
[ServiceBehavior(InstanceContextMode=InstanceContextMode.Single)]<br />
public class chat : IChat<br />
{<br />
private List<IChangedHandler> mSubscribers = new List<IChangedHandler>();<br />
<br />
public chat()<br />
{<br />
<br />
}<br />
<br />
public void Subscribe(string inName)<br />
{<br />
mSubscribers.Add(OperationContext.Current.GetCallbackChannel<IChangedHandler>());<br />
}<br />
<br />
public void Unsubscribe()<br />
{<br />
IChangedHandler caller =<br />
OperationContext.Current.GetCallbackChannel<IChangedHandler>();<br />
<br />
foreach (IChangedHandler ch in mSubscribers)<br />
{<br />
if (ch == caller)<br />
{<br />
mSubscribers.Remove(ch);<br />
break;<br />
}<br />
}<br />
}<br />
public void publishNewMessage(string inMessage, string inName)<br />
{<br />
int nIndex = 0;<br />
try<br />
{<br />
foreach (IChangedHandler ch in mSubscribers)<br />
{<br />
ch.changed(inMessage);<br />
nIndex++;<br />
}<br />
}<br />
catch (Exception ex)<br />
{<br />
mSubscribers.RemoveAt(nIndex);<br />
}<br />
}<br />
}<br />
}<br />
HOST:
My Host for this class library is a windows application project(myWCFCallBackHost), the initialize method looks likes this:
<br />
private void initializeHost()<br />
{<br />
Uri addr;<br />
try<br />
{<br />
mChat = new chat();<br />
<br />
addr = new Uri(ConfigurationManager.AppSettings["baseTcpTempService"]);<br />
mServiceHost = new ServiceHost(mChat, addr);<br />
<br />
addr = new Uri(ConfigurationManager.AppSettings["basePipeTempService"]);<br />
mServiceHost.AddServiceEndpoint(typeof(myWCFCallBackService.IChat), new NetNamedPipeBinding(), addr);<br />
<br />
mServiceHost.Open();<br />
<br />
lstStatus.Items.Insert(0, DateTime.Now.ToString() + " - Chat server is running.");<br />
}<br />
catch(Exception ex)<br />
{<br />
MessageBox.Show("Error: " + ex.Message);<br />
}<br />
}<br />
The app.config file in my host project looks like this:
<br />
appSettings><br />
add key="baseTcpTempService" value="net.tcp://localhost:9000/chat" /><br />
add key="basePipeTempService" value="net.pipe://localhost/chat" /><br />
/appSettings><br />
system.serviceModel><br />
services><br />
service name="TempSensor"><br />
endpoint<br />
address=""<br />
binding="netTcpBinding"<br />
contract="ITempChangedPub"<br />
/><br />
/service><br />
/services><br />
/system.serviceModel><br />
PROBLEM
Generate proxy:
I have earlyer built a simple wcf application with one client and one host, i was here using http binding.
By using the fallowing command i could get a proxy class(cs) and a output.config(app.config) for the client:
svcutil.exe http://localhost/myService?wsdl
This workt grate, the client could contact the host with no problems.
But now when I am using TCP i need to run svcutil on my assembly(dll) file from my Service project(myWCFCallBackService) like this:
svcutil.exe myWCFCallBackService.dll
And this generates two files(xsd and wsdl). Now i need to run svcutil.exe on this two files as well, but this will not work?
svcutil.exe tempuri.org.wsdl
Gets me the fallowing error:
Error: Cannot import wsdl:portType
Detail: An exception was thrown while running a WSDL import extension: System.Se
rviceModel.Description.DataContractSerializerMessageContractImporter
Error: Schema with target namespace 'http://tempuri.org/' could not be found.
XPath to Error Source: //wsdl:definitions[@targetNamespace='http://tempuri.org/'
]/wsdl:portType[@name='IChat']
Error: Cannot import wsdl:binding
Detail: There was an error importing a wsdl:portType that the wsdl:binding is de
pendent on.
XPath to wsdl:portType: //wsdl:definitions[@targetNamespace='http://tempuri.org/
']/wsdl:portType[@name='IChat']
XPath to Error Source: //wsdl:definitions[@targetNamespace='http://tempuri.org/'
]/wsdl:binding[@name='DefaultBinding_IChat']
Generating files...
Warning: No code was generated.
If you were trying to generate a client, this could be because the metadata docu
ments did not contain any valid contracts or services
or because all contracts/services were discovered to exist in /reference assembl
ies. Verify that you passed all the metadata documents to the tool.
Warning: If you would like to generate data contracts from schemas make sure to
use the /dataContractOnly option.
And if i run:
svcutil.exe tempuri.org.xsd
I get the fallowing error:
Generating files...
Warning: No code was generated.
If you were trying to generate a client, this could be because the metadata docu
ments did not contain any valid contracts or services
or because all contracts/services were discovered to exist in /reference assembl
ies. Verify that you passed all the metadata documents to the tool.
Warning: If you would like to generate data contracts from schemas make sure to
use the /dataContractOnly option.
I was expected a proxy class(cs) and a output.config file(app.config).
What am i doing wrong?
Other Questions
1. Am I handling the callback correct?
2. Will i get a proxy class and a config file from using svutil.exe or what will i get? and how to use them?
3. From a earlier project alot of things was placed in the Hosts app.config file insted of in the code, like this:
<br />
<?xml version="1.0" encoding="utf-8" ?><br />
<configuration><br />
<system.serviceModel><br />
<behaviors><br />
<serviceBehaviors><br />
<behavior name="myServiceTypeBehavior"><br />
<serviceMetadata httpGetEnabled="True"/><br />
</behavior><br />
</serviceBehaviors><br />
</behaviors><br />
<services><br />
<service name="myWCFServerObjectSender.personService" behaviorConfiguration="myServiceTypeBehavior"><br />
<endpoint address="http://localhost/person"<br />
binding="basicHttpBinding"<br />
contract="myWCFServerObjectSender.personService"><br />
</endpoint><br />
<endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" /><br />
</service><br />
</services><br />
</system.serviceModel><br />
</configuration><br />
Is it posible to do somthing like this with the current project? and if, how should it look like?.
Sorry for all the questions but i am learning the intressting WCF framework.
|
|
|
|
|
what are the classes present in the dotnet framework
|
|
|
|