Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5946663
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:51:17+00:00 2026-05-22T16:51:17+00:00

The code below is running without any errors but is not giving me the

  • 0

The code below is running without any errors but is not giving me the exact result.

-(id)init
{
    if (self = [super init]) {
        m_cAppIdMap = [[NSMutableDictionary alloc]init];
        //enumerator = [m_cAppIdMap keyEnumerator];
    }
    return self;
}
-(BOOL)createTimer
{
    stRs232Timer*   pEvent = malloc(sizeof(stRs232Timer));

    pEvent->bPersistent = YES;                              // setup timer structure
    //pEvent->pStack      = pStack;
    pEvent->wAppTimerId = 95;
    pEvent->uPeriod     = 50;
    pEvent->bStopped    = NO;
    wTimerId = 95;

    NSLog(@"bPersistent:%d",pEvent->bPersistent);
    NSLog(@"wAppTimerId:%d",pEvent->wAppTimerId);
    NSLog(@"uPeriod:%d",pEvent->uPeriod);
    NSLog(@"bStopped:%d",pEvent->bStopped);

    theLock = [[NSLock alloc]init];

    NSData* myData = [NSData dataWithBytes:&pEvent length:sizeof(pEvent)];
    [m_cAppIdMap setObject:myData forKey:[NSNumber numberWithUnsignedShort:wTimerId]];
    wTimerId = 96;
    [m_cAppIdMap setObject:myData forKey:[NSNumber numberWithUnsignedShort:wTimerId]];
    wTimerId = 97;
    [m_cAppIdMap setObject:myData forKey:[NSNumber numberWithUnsignedShort:wTimerId]];
    wTimerId = 98;
    [m_cAppIdMap setObject:myData forKey:[NSNumber numberWithUnsignedShort:wTimerId]];
    wTimerId = 99;
    [m_cAppIdMap setObject:myData forKey:[NSNumber numberWithUnsignedShort:wTimerId]];


    NSLog(@"The dictionary count now is:%d",[m_cAppIdMap count]);
    NSLog(@"The dictionary values now is:");
    NSLog(@"%@",m_cAppIdMap);

    [self KillTimer:wTimerId];

    if ([theLock tryLock]) {
        //wTimerId=100;
        //[m_cAppIdMap setObject:myData forKey:[NSNumber numberWithUnsignedShort:wTimerId]];
        [theLock unlock];
    }   
    int k = [m_cAppIdMap count];
    NSLog(@"The count of dict :%d",k);
    NSLog(@"My dictionary is:%@",m_cAppIdMap);
    return YES;
}
-(BOOL)KillTimer:(unsigned short)wTimerIds
{
    stRs232Timer* pEvent = malloc(sizeof(stRs232Timer));
    BOOL bReturn=NO;
    theLock = [[NSLock alloc]init];

    if ([theLock tryLock]) {

        NSLog(@"Locked");
        NSEnumerator* enumerator = [m_cAppIdMap keyEnumerator];
        id key;
        while((key = [enumerator nextObject]))
        {
            NSLog(@"Into the while loop!!");
            if ([NSNumber numberWithUnsignedShort:wTimerIds] == key) {
             NSLog(@"Got key to remove");
             //[self findAndRemoveEvent:pEvent];
             [m_cAppIdMap removeObjectForKey:[NSNumber numberWithUnsignedShort:wTimerIds]];
              NSLog(@"Removed the key");
             free(pEvent);
            }
            else {
                NSLog(@"No key with this Id");
            }

            bReturn = YES;
        }
        NSLog(@"Unlocked!!");
        [theLock unlock];
    }   

    return bReturn;
}

OUTPUT

2011-05-24 19:19:02.915 NSArray[7558:a0f] bPersistent:1
2011-05-24 19:19:02.918 NSArray[7558:a0f] wAppTimerId:95
2011-05-24 19:19:02.919 NSArray[7558:a0f] uPeriod:50
2011-05-24 19:19:02.919 NSArray[7558:a0f] bStopped:0
2011-05-24 19:19:02.920 NSArray[7558:a0f] The dictionary count now is:5
2011-05-24 19:19:02.920 NSArray[7558:a0f] The dictionary values now is:
2011-05-24 19:19:02.921 NSArray[7558:a0f] {
    98 = <70c71000 01000000>;
    97 = <70c71000 01000000>;
    96 = <70c71000 01000000>;
    99 = <70c71000 01000000>;
    95 = <70c71000 01000000>;
}
2011-05-24 19:19:02.921 NSArray[7558:a0f] Locked
2011-05-24 19:19:02.925 NSArray[7558:a0f] Into the while loop!!
2011-05-24 19:19:02.925 NSArray[7558:a0f] No key with this Id
2011-05-24 19:19:02.926 NSArray[7558:a0f] Into the while loop!!
2011-05-24 19:19:02.926 NSArray[7558:a0f] No key with this Id
2011-05-24 19:19:02.927 NSArray[7558:a0f] Into the while loop!!
2011-05-24 19:19:02.927 NSArray[7558:a0f] No key with this Id
2011-05-24 19:19:02.927 NSArray[7558:a0f] Into the while loop!!
2011-05-24 19:19:02.928 NSArray[7558:a0f] No key with this Id
2011-05-24 19:19:02.928 NSArray[7558:a0f] Into the while loop!!
2011-05-24 19:19:02.929 NSArray[7558:a0f] No key with this Id
2011-05-24 19:19:02.929 NSArray[7558:a0f] Unlocked!!
2011-05-24 19:19:02.930 NSArray[7558:a0f] The count of dict :5
2011-05-24 19:19:02.930 NSArray[7558:a0f] My dictionary is:{
    98 = <70c71000 01000000>;
    97 = <70c71000 01000000>;
    96 = <70c71000 01000000>;
    99 = <70c71000 01000000>;
    95 = <70c71000 01000000>;
}

In the code above i’m deleting the value corresponding to the key(wTimerId = 95).But
Though the key is existing its not getting into the if loop and deleting the corresponding
key value pair.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T16:51:18+00:00Added an answer on May 22, 2026 at 4:51 pm

    You are checking for the same address here [NSNumber numberWithUnsignedShort:wTimerIds] == key rather than the same object. Try

    ...
    if ( [[NSNumber numberWithUnsignedShort:wTimerIds] isEqual:key] ) {
    ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When running the below code a type is never returned, despite there being a
Hello friends i am running code given below which contains the setLogTimeEntery function and
Code below does not run correctly and throws InvalidOperationExcepiton . public void Foo() {
Code below is not working as expected to detect if it is in design
The code below works. But if I comment out the line Dim objRequest As
The code below gives an error: Property 'Int32 Key' is not defined for type
The offending block of code is below. The code almost always works, but sometimes
I am joining two images using the code below but it throws an OutOfMemory
Apologies for the lack of a code example but I'm not sure I could
Code below is working well as long as I have class ClassSameAssembly in same

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.