|
Thanks for taking time to respond to my question. I'm going over a threading sample from MSDN and is having a hard time trying to understand the sample:
(a) Monitor.Wait
(b) Monitor.Pulse
(c) waiting Vs ready queue in context of threading
(d) Why you need to add a "readerFlag" in the resource you are acquiring a lock on when you have already locked the resource using "lock( )" statement.
Before going further, reference to MSDN here:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/csref/html/vcwlkthreadingtutorial.asp
QUESTION 1:
"A lot of times there are a couple of steps to locking an object"
>> Q1-a: I don't get it. To lock and unlock an object:
Monitor.Enter(thisObj); //This won't return until you get the lock
thisObj.DoSomething();
Monitor.Exit(thisObj);
To try to lock and obj, use Monitor.TryEnter instead. But, in our MSDN sample:
public void WriteToCell(int n)
{
lock(this) // Enter synchronization block: The "lock()" block.
{
if (readerFlag)
{ // Why do you need this flag if you have already "lock" the resource???
}
} // Q1-b: Lock release here - my understanding correct?? This means you can do whatever you want in the "lock" block.? (Exiting THE "lock()"-block)
}
}
>> Q1-c: Once you acquire the lock (via Monitor.Enter or lock() function as in sample), NO other thread can acquire lock on "thisObj" until "Monitor.Exit". There's NO need for "readerFlag".
QUESTION 2:
Quote:
"Now that the cook is done, you go "hey over there, it's my turn! No one else is allowed to cut in front of me!" so you call
[
Monitor.Wait(this);
]"
>> Q2-a: Doesn't Wait function surrender lock to resource to next thread in "waiting queue". According to MSDN, Wait() does this:
* "Releases the lock on an object in order to permit other threads (in waiting queue) to lock and access the object."
* "Releases the lock on an object and blocks the current thread until it reacquires the lock."
My question is, why release lock BEFORE you actually do something (Read) with reseource?
public int ReadFromCell( )
{
lock(this) // Enter synchronization block: The "lock()"-block
{
if (!readerFlag) //WhY?? You ALREADY have the lock on "this" resource.
{
try
{
// Again, WHY!? You ALREADY have lock on "this" resource.
Monitor.Wait(this);
}
... catch statements...
}
Console.WriteLine("Consume: {0}",cellContents); //Q2-b: NOW you're reading - but why can't you read immediately after "lock(this)" statement???
readerFlag = false; // Q2-c: I have no idea why we need this flag.
// is done.
Monitor.Pulse(this); // Q2-d: I have no idea why we need to pulse - exitining the "lock()" block surrender the lock, other threads waiting for the resources will naturally be able to acquire it once execution exit the "lock()" block, why Pulse???
} // Exit synchronization block: The "lock()"-block
return cellContents;
}
>> Q2-f: waiting queue Vs ready queue - What the... It's in Monitor class documentation (.NET framework).
Help!
|
|
|
|
|
|
Well explained, let me go back and see if I truely understand it. Thanks.
norm
|
|
|
|
|
Thanks a lot, gone thru the sample today.
norm
|
|
|
|
|
When I developing my webservice can I edit WSDL file? I can't find this file in the folder of XML application.It create in my consumer application when I addd reference to it, so does this file create on the server?
Mazy
No sig. available now.
|
|
|
|
|
The WSDL is generated by passing a parameter to the webservice's .asmx file.
For the CP webservice (http://www.codeproject.com/webservices/latest.asmx) the WSDL is at: http://www.codeproject.com/webservices/latest.asmx?WSDL
Mazdak wrote:
When I developing my webservice can I edit WSDL file?
I don't think so, I think .NET always generates the WSDL file based on what the webservice offers.
James
"My words but a whisper -- your deafness a SHOUT.
I may make you feel but I can't make you think." - Thick as a Brick, Jethro Tull 1972
|
|
|
|
|
Do a search for the wsdl file
or using the .net prompt type
wsdl /language:CS /out:<filename>.cs <webservicename>.wsdl
this creates your wsdl file or just do a serach for *.wsdl
its an xml file so you can easily edit it in vs, notepad, xml spy or whatever although I dont know of any valid reason to.
you can do it throuogh the IDE and then just edit it there
nick
I'm not an expert yet, but I play one at work. Yeah and here too.
|
|
|
|
|
Thanks for reply james.
Ista wrote:
you can do it throuogh the IDE and then just edit it there
But where can I save it? When user request it how can I force VS.NET use my wsdl, not create its own version?
Mazy
No sig. available now.
|
|
|
|
|
Its created based on your asmx file. What exactly are you trying to do so I can fully understand why you are trying to change it.
You might want to change the web service attributes in your class inorder to change that file. Because it is created based on your your web attributes and what not. Are you trying to build custom wsdl by client or what?
nick
I'm not an expert yet, but I play one at work. Yeah and here too.
|
|
|
|
|
Hello all
I'm trying to create a logon web application and would like to check the validity of a new user's email address...
apart from string searching for '@' and '.' etc
I would like to check that the server exists and that there is an account for the new user (maybe use a ping somehow)
Thanks a lot
gil s
|
|
|
|
|
|
I've published, in a first cut form, our plugin to Visual Studio .NET to
support integrated test runs of NUnit tests, complete with integrated
debugger support. It's totally free, and pretty handy -- please report your
bugs to help us improve it.
http://www.mailframe.net/Products/TestRunner.htm
|
|
|
|
|
this code shows me the current line and character index in a richtextbox control. the char index, however, is counted from position 0 at line 0 but i need the char index to start from 0 at each line and NOT from line 0.
how can i do this?
private void rtb1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)<br />
{<br />
<br />
int Line = rtb1.GetLineFromCharIndex(rtb1.SelectionStart);<br />
MessageBox.Show(Line.ToString());<br />
<br />
int pos = rtb1.GetCharIndexFromPosition(new Point(e.X, e.Y));<br />
MessageBox.Show(pos.ToString());<br />
<br />
}
Thanks for your help.
.gonad
|
|
|
|
|
the only way I might see is if you do this:
int Line = rtb1.GetLineFromCharIndex(rtb1.SelectionStart);
int pos = rtb1.SelectionStart;
while ( (newLine = rtb1.GetLineFromCharIndex(pos--) == Line)
MessageBox.Show("The beginning char index of the line is " + ++pos.ToString());
now that code is not tested I just typed it in but it should work for the char index of the first Line
MessageBox.Show(String.Format("Your caret is {0} characters away from the beginning",rtf1.SelectionStart - pos);
I'm not an expert yet, but I play one at work. Yeah and here too.
|
|
|
|
|
It's a static method - no constructor needed.
System.Windows.Forms.MessageBox.Show("You must enter a name.",
"Name Entry Error",MessageBoxButtons.OK,
MessageBoxIcon.Exclamation);
"Blessed are the peacemakers, for they shall be called sons of God." - Jesus
"You must be the change you wish to see in the world." - Mahatma Gandhi
|
|
|
|
|
uhh what are you talking about?
maybe its the wrong question assigned. lol
I'm not an expert yet, but I play one at work. Yeah and here too.
|
|
|
|
|
Hi,
I'm working on a POS project using C# .NET. For now, I don't have a barcode reader and a receipt printer which are definitly a MUST for a POS system in the future.
I would like to know the nature of these two things, so that when i program the POS system, I know how to program as a way of using these two things.
I cannot purchase these two items before the completion of the project. So, I totally cannot try in my program or even know what it is. I want to program my system so that i do not need to have a big modification when i purchase these two things afterward.
Please help!
|
|
|
|
|
I have worked on a few POS systems in the past.
There are a few things to take into consideration.
1. What type of barcode scanner do you plan to use. If you are using a a wedge reader then the data that is read will be just like pasting a block of text into a edit box and it can be read simply. If the scanner is a COM port based scanner you will need to write a device driver or serial port capture routines to read the data. There is a good serail port class on this site http://www.codeproject.com/system/cserialport.asp.
2. Which barcode will you be using ??? Sometimes the barcode will contain additional characters that you are not interested in. The data that will be read in may have an extra characters at the start and/or end (e.g. check digit) depending on the barcode type and reader. Usually POS systems use the barcode EAN-13 (european standard) or EAN-8 (Which I think is the US standard)
3. POS Printer. You can simulate having a POS Printer. Do you have access to a printer? The only real programming difference between a POS printer is the width of the paper. You can setup your printer with a custom size paper that matches the width of the intended POS reciept printer and it will be just as if you has the receipt printer.
Hope this helps.
|
|
|
|
|
Thank you very much!!!! Your advice helps me a lot@!!!! Thanks
AdrianT wrote:
1. What type of barcode scanner do you plan to use.
I don't know. But i think I will look for some reader that support USB. And I heard from someone that some reader plug into the PS/2 port (for keyboard or mouse..). Am I thinking something right?
AdrianT wrote:
If you are using a a wedge reader
What is wedge reader? (i guess normal reader that plug in keyboard wedge or USB? i saw something: USB Adapter for Keyboard Wedge Barcode Scanners from web http://www.skandata.com/usb.html. So I guess wedge is that "plug" for keyboard??!! )
AdrianT wrote:
then the data that is read will be just like pasting a block of text into a edit box and it can be read simply.
Is that mean after reading the barcode, it just acts as a person typing character from keyboard or number pad then leave it there? (no return or ENTER signal?)
AdrianT wrote:
2. Which barcode will you be using ???
I think I will use the American standard (i'm in Canada). Since it is a bookstore POS, I will use the barcode behind each books or cards and print some barcodes by my own for other items (such as gift)
AdrianT wrote:
3. POS Printer.
That means i can just set the page size as small as a receipt, then use my home printer to simulate it...right? Oh.....easy...haha...
THANK YOU VERY MUCH!!!!!! ;);P
|
|
|
|
|
if its an object why not include general methods that can be adapted later
I'm not an expert yet, but I play one at work. Yeah and here too.
|
|
|
|
|
hi,
QUESTION 1: i understand you can add modifier to interface:
public interface IA
{
public void DoA(); //Yes, I understand this is INVALID - so, I didnt do this.
void DoB();
void DoC();
double salary
{
get;
}
}
But I thought access modifier is OK when you declare implementation in class? I tried access access modifier in class but the compiler keep bitching that it's NOT legal to do so - and it didnt provide error code (like C1324)! See "QUESTION" below:
public class Capitalist : IA, IB, ICapitalist //QUESTION 2: Can you specify public/private... in interface inheritance? How?
{
//Implement interface IA:
public void IA.DoA() //QUESTION 1: compiler complained here!!
{
Console.WriteLine("Capitalist.IA.DoA");
return;
}
void IA.DoB() //This, on the other hand, is oK.
{
Console.WriteLine("Capitalist.IA.DoB");
return;
}
... and the rest of it ...
}
THanks!
norm
|
|
|
|
|
|
You can append access modifer when you implement it in a class, PROVIDED that the interface is not the base interface of another interface that the class implements.
Using example below, IAccMaintenance is the base interface of IAccManager:
interface IAccMaintenance
{
int EditAccProfile(...); //DO NOT append access modifer to this method when you implement it.
}
interface IAccManager : IAccMaintenance
{
...
}
Now, when you implement it in a class:
class SiteManager : IAccManager
{
public int IAccManager.CreateAcc(...) {...} //That's OK. You can use access modifier here.
public int EditAccProfile(...) {...} //ERROR: You can't use access modifier - the method comes from an interface that's not directly inherited. But why would .NET team design it this way???
...
}
***********************************************************************
In case you want to just compile the code and see...
using System;
namespace try_interface2
{
public interface IAccMaintenance
{
int EditAccProfile(int accID);
}
public interface IOldAccMaintenance
{
int EditAccProfile(int accID);
}
public interface IAccManager : IAccMaintenance, IOldAccMaintenance
{
int CreateAcc(string accType, int accID);
int DestroyAcc(int accID);
int numAccount
{
get;
set;
}
}
interface IConnManager
{
int Connect(string Destination, int connID);
int Disconn(int connID);
}
class CSiteManager : IAccManager, IConnManager
{
protected int m_numAccount;
//(1) Implementing IAccManager interface:
public int CreateAcc(string accType, int accID)
{
Console.WriteLine("CreateAcc... account type: {0}, account ID: {1}", accType, accID.ToString());
return 1;
}
public int DestroyAcc(int accID)
{
Console.WriteLine("Destroy Acc... account ID: {0}", accID.ToString());
return 1;
}
public int numAccount
{
get{ return m_numAccount; }
set{ m_numAccount=value; }
}
int IAccMaintenance.EditAccProfile(int accID)
{
int err=0;
Console.WriteLine("edit acc profile ver 0. accID: {0}", accID);
return err;
}
int IOldAccMaintenance.EditAccProfile(int accID)
{
int err=0;
Console.WriteLine("edit acc profile ver 0. accID: {0}", accID);
return err;
}
//(2) Implementing IConnManager interface (Default method access modifier: private):
int IConnManager.Connect(string Destination, int connID)
{
int err=0;
Console.WriteLine("Connect... destination: {0} connID: {1}", Destination, connID);
return err;
}
int IConnManager.Disconn(int connID)
{
int err=0;
Console.WriteLine("Disconn... connID: {0}", connID);
return err;
}
}
///
/// Summary description for Class1.
///
class AppClass
{
///
/// The main entry point for the application.
///
[STAThread]
static void Main(string[] args)
{
CSiteManager siteManager = new CSiteManager();
siteManager.CreateAcc("developer_premimum", 731);
siteManager.DestroyAcc(423);
siteManager.numAccount = 14302;
Console.WriteLine("Number of registered accounts: {0}", siteManager.numAccount);
}
}
}
norm
|
|
|
|
|
From MSDN[^]:
All interface members implicitly have public access. It is a compile-time error for interface member declarations to include any modifiers. In particular, interfaces members cannot be declared with the modifiers abstract, public, protected, internal, private, virtual, override, or static.
Hope this helps.
α.γεεκ Fortune passes everywhere. Duke Leto Atreides
|
|
|
|
|
i know. That's why I didn't add any access modifier in interface declaration. But in the class that implements it... the code is below, compile it and see for yourself:
using System;
namespace deda
{ //namespace deda
public interface IA
{
void DoA();
void DoB();
void DoC();
double salary
{
get;
}
}
public interface IB : IA
{
new void DoA();
}
public interface ICapitalist
{
void HireSlave();
void FireSlave();
}
public class Capitalist : IA, IB, ICapitalist
{
//Implement interface IA:
public void IA.DoA()
{
Console.WriteLine("Capitalist.IA.DoA");
return;
}
void IA.DoB()
{
Console.WriteLine("Capitalist.IA.DoB");
return;
}
void IA.DoC()
{
Console.WriteLine("Capitalist.IA.DoC");
return;
}
public double salary {
get{ return m_salary;}
}
//Implement interface IB:
void IB.DoA()
{
Console.WriteLine("Capitalist.IB.DoA");
return;
}
//Implement interface ICapitalist:
void ICapitalist.HireSlave(){
Console.WriteLine("Capitalist hiring");
return;
}
void ICapitalist.FireSlave(){
Console.WriteLine("Capitalist layoff people");
return;
}
//Class' protected attributes:
protected double m_salary;
}
} //namespace deda
norm
|
|
|
|