threads accessing private methods

Hi!

Here is a simple example on a timer accessing the private method 
timer_Elapsed. This works fine.
In this example one might consider that the timer_Elapsed must be public 
because the one that is calling is not
within the class.
So I just wonder is it always in such a way that when the framework or the 
OS is calling upon a method it can be declared as
private and it will work ?
class Test
{
    static void Main()
    {
         Timer timer = new Timer();
         timer.Elapsed += new ElapsedEventHandler(timer_Elapsed);
         timer.Interval = 1000;
         timer.Enabled = true;
         Console.ReadLine();
   }

    private static void timer_Elapsed(object sender, ElapsedEventArgs e)
    {
       Console.WriteLine("Working");
    }
}

//Tony 


0
Tony
3/18/2010 8:08:38 AM
dotnet.languages.csharp 1931 articles. 0 followers. Follow

3 Replies
545 Views

Similar Articles

[PageSpeed] 10

Tony Johansson wrote:
> Hi!
> 
> Here is a simple example on a timer accessing the private method 
> timer_Elapsed. This works fine.
> In this example one might consider that the timer_Elapsed must be public 
> because the one that is calling is not
> within the class.
> So I just wonder is it always in such a way that when the framework or the 
> OS is calling upon a method it can be declared as
> private and it will work ?
> class Test
> {
>     static void Main()
>     {
>          Timer timer = new Timer();
>          timer.Elapsed += new ElapsedEventHandler(timer_Elapsed);
>          timer.Interval = 1000;
>          timer.Enabled = true;
>          Console.ReadLine();
>    }
> 
>     private static void timer_Elapsed(object sender, ElapsedEventArgs e)
>     {
>        Console.WriteLine("Working");
>     }
> }
> 
> //Tony 
> 

As the delegate contains a reference to the method, it doesn't matter if 
the method is private or not. When the method is called the reference is 
used, so whatever is using the delegate doesn't need access to the 
method by name.

-- 
G�ran Andersson
_____
http://www.guffa.com
0
ISO
3/18/2010 3:07:04 PM
Tony Johansson wrote:
> Hi!
> 
> Here is a simple example on a timer accessing the private method 
> timer_Elapsed. This works fine.
> In this example one might consider that the timer_Elapsed must be public 
> because the one that is calling is not
> within the class.

In addition to what G�ran wrote, I want to also point out that which 
_thread_ is used to execute a method has nothing at all to do with the 
accessibility of the method.  That is, threads aren't related to 
accessibility at all.

Your "Subject:" seems to imply that you believe they are.

Pete
0
Peter
3/18/2010 3:54:22 PM
Peter Duniho wrote:
> Tony Johansson wrote:
>> Hi!
>>
>> Here is a simple example on a timer accessing the private method 
>> timer_Elapsed. This works fine.
>> In this example one might consider that the timer_Elapsed must be 
>> public because the one that is calling is not
>> within the class.
> 
> In addition to what G�ran wrote, I want to also point out that which 
> _thread_ is used to execute a method has nothing at all to do with the 
> accessibility of the method.  That is, threads aren't related to 
> accessibility at all.
> 
> Your "Subject:" seems to imply that you believe they are.

Particularly since in the example given, the calling method and the 
called method ARE static methods from the same class.
0
Harlan
3/18/2010 4:19:30 PM
Reply:

Similar Artilces:

Instant Access not enabled.
At start-up of Excel I get a pop-up which states: "Unable to Find Quit on the File Menu. Instant Access not enabled." I can then choose to press OK on the pop-up, after which everything works OK and Instant Access does work. I believe Quit is on the File Menu: it's the X mark to quit Excel completely. I also have an add-on icon which I can't get rid of (couldn't get rid of it in Excel 2000 either), as it keeps coming back, even though it says it can't come back and will be irretrievable. This add-on is for an old scanner that I no longer use and have deleted ...

Microsoft CRM 3.0 with Microsoft Outlook Web Access
Is it existing un plugin for Microsoft Outlook Web Access. I installed the client for Outlook. Is somebody can help me Thanks ...

Can't change authentication methods on HTTP Virtual Server
Trying to change Authentication Methods for Exchange properties in my HTTP Virtual Server and it is grayed out. I read a document explaining not to use IIS console to do this. Well, I can't do it from here. I am not sure if this is some kind of a security setting. I am logged in as Administrator. Help is greatly appreciated Are you trying to do this from Exchange System Manager, Server, Protocols, HTTP, Exchange Virtual Server? If so, you are correct, you should not make changes through here. You want to change it throuhg IIS. Go to Start, Program Files, Administrative Tools, Interne...

How to manipulate Outlook data from MS Access
When the Calendar folder is used as a linked table in MS Access, only some fields are shown. Is there a way to have them all? The linked table method has major limitations, including the inability = to show even all the reasonably important fields. While articles have = been written on how to expand on this method's obvious features, I've = never been able to duplicate the results. See = http://www.outlookcode.com/d/database.htm#linkedtables .=20 That page will also give you other ideas on how to work with databases = and Outlook together. You'll need to write code or use a t...

Outside programs accessing wrong Outlook account when sending
A program designed by one of our technicians attempts to send out an emergency email to multiple email addresses, using Microsoft Outlook 2002. However, the mail message attempts to send thru our Exchange server, instead of the SMTP it is supposed to be using. The Exchange is not set up to send mail out of our university for security reasons, yet Outlook will not allow me to redirect those mails thru our SMTP server. The SMTP is set up as the default on every user's machine here, but these emails skip right past it. Any suggestions would be greatly appreciated. Is the Outlook pr...

how can i make a in-process report that can be accessed by severa.
i need to set up an in-process report that can be accessed by several users at once, in which every user can input data without shutting down the workbooks on the remaining computer so that the one user can do his inputting. Hi you could use 'Tools - share workbook' BUT: - several functions are then no longer available (see Excêl's help for details' - IMHO Excel is NOT designed for multi-user access. Use a database application instead -- Regards Frank Kabel Frankfurt, Germany "tim" <tim@discussions.microsoft.com> schrieb im Newsbeitrag news:E5B2A371-4...

access denied
cannot open completed worksheet from folder that is in My documents. Cannot do anything with it. ...

How do I change the action of button in Access 2007 contact list?
I need to change the email address manually when I click the "send email" button to create new email directly from Contact List of Access 2007 as the default email address is including the receiver name (name + emal address was recognized as wrong email address by Windows Live Mail). How to change the default setting of Access 2007? -- THANKS & BEST REGARDS, Nguyen Tung Director of Sales and Marketing --------------------------------------- THIENTHAONGUYEN TRANSPORTATION CO., No181 Dai Tu Str,Hoang Mai Dist,Hanoi,Vietnam Tel :(84.4) 36410 577 - 107 /...

question regarding access
So here is the situation.. Dual booting win vista business and win 7 ultimate on 1 partitioned drive and all games and docs on another drive. Games I have added are accessible from vista as they have always been but I cannot seem to get them to play from win 7. In vista when I click on the shortcut for 1 particular game it starts with no problem however even after copying the shortcut from the vista side to win 7 it asks me to buy/unlock the game even though I own it and have for 3 years. Is there something simple I am missing here? I do not really want to buy it again or sta...

Access Bulletin Board? Acess/Excel Jobs?
Just wondering if anyone might know of online resources providing info pertaining to Access or Excel software positions. How does a person go about finding such positions? CareerBuilder, Monster, HotJobs? Is there someplace more specific? Is this the kind of thing that generally requires referral? "David Portwood" <Mondrogan@yahoo.com> wrote > Just wondering if anyone might know of online > resources providing info pertaining to Access or > Excel software positions. How does a person go about > finding such positions? There seem to be fewer jobs, these ...

Outlook Web Access #17
I am trying to have Outlook Web access run in IIS 6 on a Windows 2003 server. Half of the mailboxes in the company are on the message store on this Windows 2003 server and the other half are on another message store on another server. We have a web site where a use clicks on a link to go to http://192.168.42.7/exchange where 192.168.42.7 is the location of the Windows 2003 server. If a user's mailbox is on this server then the link works fine and they can see their mail. If the user is on the other server they get the error message page not found, dns error or server error. How...

Showing the actual database, not access's idea of it...
I've been working with MS Access for the past few weeks. A friend has a side job working for a summer camp and he needed a database to store all the kids information. Using VBA is not going to happen, I thought I could do what he needed much much easier in visual studios.net 2008 and I probably could have if that department of Microsoft didn't do what appears as drastic as disown the MS Access department. After much work I am able to read/replace and edit the data, but through the whole process I started noticing this. First, in Access the ID(auto number) is listed co...

Programmatic Access Security Pop up with Wordeditor
Outlook 2007 SP2 Exchange 2007 SP1 I want to create a task with an formated hyperlink in the body. At Set objDoc = objInsp.WordEditor always security boxes pop up !!!!! Why???? This is the Code: Private Sub CreateNewTaskWithHyperlink() Dim appOutLook As Outlook.Application Dim taskOutLook As Outlook.TaskItem Dim objInsp As Outlook.Inspector Dim objSel As Word.Selection Dim strLink As String Dim strLinkText As String Dim olAnw As Object Dim docangebot As Word.Document Set docangebot = ActiveDocument 'Only For test fix Hyperli...

How do I add a grouping level to an existing report in Access?
How do I add a grouping level to an existing report in Access? In report design view, show the Sorting and Grouping dialog (View menu.) Click the "record selector" at the left of the field where you want a row above. Tap the Insert key. -- Allen Browne - Microsoft MVP. Perth, Western Australia Tips for Access users - http://allenbrowne.com/tips.html Reply to group, rather than allenbrowne at mvps dot org. "latwood" <latwood@discussions.microsoft.com> wrote in message news:D49F7C44-8E44-4547-811C-ABC492917A75@microsoft.com... > How do I add a grouping level ...

Access data transfer
Hello, I have been looking for a data integration / transfer program able to help with Access and also Mysql. I have had some advice but have not found the right software yet. The main feature is being able to migrate important quantities of contacts and data on a daily basis. The migration would be done manually. Thank you for your help! Access has pretty robuse import and export capabilities. Describe in greater detail what you need to transfer and what file structure is required. -- Jerry Whittle, Microsoft Access MVP Light. Strong. Cheap. Pick two. Keith Bontrage...

excel calculations in Access
Hi, I have a complex query written in Excel which i want to replicate in Access, however when i do it flags a error message saying undefined functions. So i'm looking for the eqivualents in Access. The ones it can't find are: SQRT - Which i believe is just SQR in access CHIINV NORMSINV So if anyone can help with this i'd be most grateful. If needed the full access query as it stands at the minute is as follows; Expr1: [T03 - Workings with Calcs]![DSR Rate]/100000+SQRT([T03 - Workings with Calcs]![Calc2 Total]/[T03 - Workings with Calcs]![SumOfStaTOT]^2/[T03 - ...

upgrade for access 97
I'm still running access 97 and am buying a new pc 64 bit windows 7. Is there any way I can upgrade or make it possible to use this program? Thanks -- Faith Hi Faith, I'm not sure if Access 97 includes any 16-bit code. If it does, then it simply will not run on a 64-bit system. You could always purchase and install VMWare Workstation, which allows you to create virtual machines. You will need a licensed copy of the operating system, and any software that you install into a virtual machine. What identified need do you have for running a 64-bit operating system...

where can i store my personal templates and have access from excel
I have office 2010 beta installed and am having trouble finding a location to store my personal templates to and have access from all my office 2010 programs ...

WriteFile access error on UMDF USB driver
I am creating a driver based on the UMDF FX2_driver sample. My device differs in that it has one input and one output interrupt endpoint. Also am providing a symbolic name. I have a test application I would like to use with this driver/device that uses WriteFile to send data to the driver. I am able to verify thru tracing and a line trace that the data from the WriteFile is being received by the driver and passed on to the usb device. However, the WriteFile fails with a GetLastError() of 1117 (ERROR_IO_DEVICE). Need to determine why I am getting this error. ricobandito &l...

Access 2007: Escape Out of Compacting Corrupts Database
Access 2007 We have a rather complicated application that has the front end set to compact on close. During the QA process our testers were able to corrupt the front end by hitting the escape key a few times while the front end was compacting. Lots of nasty popup messages when the application was restarted. We created a simple database with one table and one form (see attached). The form has three buttons: Populate Data -- This empties the table and then adds a little over one million records. View Data -- This opens the table in normal mode. DoCmd.Quit -- This issues ...

Using Access 2000 packaging and deployment wizard
Hi In Access 2000 when I open a module in my app and from Addins menu run the Access 2000 packaging and distribution wizard, it cerates the distribution package with the original MDB. How can I make it instead include the MDE of the app instead? Thanks Regards ...

limit domain admin group access in Exchange environment
We have exchange 2003 and we need to limit the access the domain admins have from editing accounts but it still allows them to view key fuctions like view the Exchange server manager console, but are not able to edit the mailboxes or accounts. Thanks Right, you shouldn't make those people "Domain Admins". They should have rights only on applicable OUs. -- Ed Crowley MVP - Exchange "Protecting the world from PSTs and brick backups!" "Joe" <Joe@discussions.microsoft.com> wrote in message news:E2CE5FB8-C280-4213-8828-2C7B860524C6@microsoft.com......

Display a count of unique records in a query in Access 2007
Hi, I'm not sure if I should be in this group, or Reports, but I'll start here. I have a user who would like to do a count of unique records and display the information in a query, or a report. Here are the basics: She has a list of donors, some of the donors donate more than once to the same cause. What she would like is a list of the number of donors, per cause. But, if the donor ID repeats for the same cause, she does not want that ID counted again. Example: We can get a query to return a count of the records per cause. It is returning a value of "7" for a cause,...

string comparsion using access--help
Hi I using access 2003. I am trying to compare data from two tables. Table A and Table B. Table A has 12 digits in 1 column and table b has 10 digits in 1 column. I need to compare Table A data starting in position 2 and ending in positon 11. I tried using instr function but it did not work. SELECT A.ItemLookupCode, B.ItemLookupCode FROM A, B WHERE InStr(2, A.ItemLookupCode, B.ItemLookupCode,11, COMPARE) Thanks Cbs On Jun 28, 1:56 pm, "Cheryl" <cboxiesc...@mindspring.com> wrote: > Hi > I using access 2003. I am trying to compare data from two table...

outlook web access #38
When I click on the address book icon in Outlook for Web 2003 it i empty. However if I type in a name on the search function th information on the individual appears from the global address book. Ho can I get the global address book to show all entries when it is evoke from outlook for web as it does for outlook 2003 locally. Also I ca only see the last 25 emails when I check email from outlook for web. I there any way to display all emails in the in-box. I appreciate an help I canget ----------------------------------------------- ~~ Message posted from http://www.ExcelTip.com ~~View and po...