Rectangle 27 5

The difficult part is not having machine B update, but rather defining precisely how you want B to update. For instance:

  • What if on machine B, the branch that is checked out is deploy, but I've made some changes there and checked them in, and now I make changes on A and force-push to deploy and there would be a merge conflict if this were a real merge? (In fact, merge does not really apply on push, as I'll describe in a bit more detail below.)

These questions rarely have a single right answer. That's why git push has the receive.denyCurrentBranch option in the first place: if the answer to the first question above is assumed to be no (it usually is no), then only updating the currently-checked-out branch raises the remaining questions. If we deny the ability to do that, why then, all those questions vanish and we don't have to think hard about the answers! :-)

There's a simple way to sidestep all of this, which is to have a bare repository on the receiving machine, and then what you might call a "bare work tree" (no .git directory in it) somewhere else on that same machine. That way there's no direct notion of "current branch" in the first place (although it sneaks back in through the back door, as it were).

There's a fundamental asymmetry here in git, in that when you git fetch from a remote, you get commits and other objects from them, stuff those in your repository, and then update your remote branches. After git fetch origin you may have a new origin/master, but you do not have a new master. This gives you a stopping point, an intermediate step, during which you get to pause, rest a bit, look at what's just come in, and decide whether and how to rebase or merge the changes.

When you git push c0ffee3:master to a remote, however, you send your commits and other objects over and they (the remote) stuff the objects into their repository, and then they update their branch master to your commit (which is also now their commit) whose ID is c0ffee3. There's no pause for evaluation; there's no chance to rebase or merge; you've replaced their master with your c0ffee3. For that matter, your c0ffee3 does not have to be your master at all. Any suitable repository objectthat's any commit ID or any annotated tag IDis sufficient if you force-push (provided there's no fancy remote hook to deny you).

All that said, though, let's go back to the "bare work tree" idea. Here, on machine Blet's stop calling this "the remote" now, and just say "here on B"we'll have a bare repository so that we can take incoming pushes regardless of what git may think is the "current branch".

Next, we'll answer the "what if" questions with this: *whenever we receive anything new for some branch(es), we'll completely blow away whatever we had before, no matter what we're in the middle of doing with it, and replace it with new stuff based on what we now believe to be in that branch or those branches."

(Is that really the right answer? What if we're in the middle of compiling or testing? Well, we claimed it was the right answer; onward.)

What we'll do here on B, then, is set up our --bare repository with a hookthis can be the post-update hook or the post-receive hookthat runs after some branch(es) is/are updated. Both "post" hooks are run just once per receive (basically once for each push), and given a list of all updates. The post-update hook gets all updated ref-names as arguments, while the post-receive hook gets all updated refs, including both old and new SHA-1s, on stdin.

(The complexity here is that in one push, I can update more than one branch and/or tag. For instance, with git push c0ffee3:master badf00d:refs/tags/new-tag, I can tell you to update your master branch to make it point to commit c0ffee3, and to create a tag pointing to object badf00d. Here, your post-update hook would get refs/heads/master refs/tags/new-tag, while your post-receive hook would be able to read two lines, roughly oldsha1 c0ffee3 refs/heads/master and then 0000000 badf00d refs/tags/new-tag, from stdin. These would all be full 40-character SHA-1s of course.)

Because we've decided that we'll just blow away the "bare work tree", all we have to do in this hook is find out if an interesting branch has been updated. Let's say we care specifically (and only) about a branch named develop, i.e., the ref-name refs/heads/develop. Then in a post-receive hook written as a shell script, our stdin scan loop might look like this:

do_update=false
while read oldsha newsha ref; do
    [ $ref = refs/heads/develop ] && do_update=true
done

In a post-update hook, we would just check arguments:

do_update=false
for ref do
    [ $ref = refs/heads/develop ] && do_update=true
done

Either way, if we see that the interesting branch has changed, we now want to do the blow-away-and-rebuild step:

blow_away_and_rebuild()
{
    local target_dir=$1 branch=$2

    rm -rf $target_dir
    mkdir $target_dir
    GIT_WORK_TREE=$target_dir git checkout -f $target_dir
}

if $do_update; then
    blow_away_and_rebuild /home/me/develop.dir develop
fi
exit 0 # succeed, regardless of actual success

Note that the git checkout step above populates the (removed and re-created) "bare work tree", but also has the side effect of setting the "current branch" (and fussing with git's index). This is how "current branch" manages to sneak in even though we have a nominally bare repository. We often don't need the rm -rf step, but if you have two different branches you'll "deploy" in this fashion, it sidesteps the "single current branch = single index" model git uses, which otherwise may leave old files behind.

The other trick here is that since /home/me/develop.dir has no .git directory within it (hence "bare work tree"), I won't be fooled into going into it, checking out a branch, and starting to edit there. Of course I can still be fooled into going into it and starting to work there, but at least I won't blame git if suddenly all my work gets rm -rf-ed. :-)

How can I push and automatically update working copy of my non-bare re...

git
Rectangle 27 5

The difficult part is not having machine B update, but rather defining precisely how you want B to update. For instance:

  • What if on machine B, the branch that is checked out is deploy, but I've made some changes there and checked them in, and now I make changes on A and force-push to deploy and there would be a merge conflict if this were a real merge? (In fact, merge does not really apply on push, as I'll describe in a bit more detail below.)

These questions rarely have a single right answer. That's why git push has the receive.denyCurrentBranch option in the first place: if the answer to the first question above is assumed to be no (it usually is no), then only updating the currently-checked-out branch raises the remaining questions. If we deny the ability to do that, why then, all those questions vanish and we don't have to think hard about the answers! :-)

There's a simple way to sidestep all of this, which is to have a bare repository on the receiving machine, and then what you might call a "bare work tree" (no .git directory in it) somewhere else on that same machine. That way there's no direct notion of "current branch" in the first place (although it sneaks back in through the back door, as it were).

There's a fundamental asymmetry here in git, in that when you git fetch from a remote, you get commits and other objects from them, stuff those in your repository, and then update your remote branches. After git fetch origin you may have a new origin/master, but you do not have a new master. This gives you a stopping point, an intermediate step, during which you get to pause, rest a bit, look at what's just come in, and decide whether and how to rebase or merge the changes.

When you git push c0ffee3:master to a remote, however, you send your commits and other objects over and they (the remote) stuff the objects into their repository, and then they update their branch master to your commit (which is also now their commit) whose ID is c0ffee3. There's no pause for evaluation; there's no chance to rebase or merge; you've replaced their master with your c0ffee3. For that matter, your c0ffee3 does not have to be your master at all. Any suitable repository objectthat's any commit ID or any annotated tag IDis sufficient if you force-push (provided there's no fancy remote hook to deny you).

All that said, though, let's go back to the "bare work tree" idea. Here, on machine Blet's stop calling this "the remote" now, and just say "here on B"we'll have a bare repository so that we can take incoming pushes regardless of what git may think is the "current branch".

Next, we'll answer the "what if" questions with this: *whenever we receive anything new for some branch(es), we'll completely blow away whatever we had before, no matter what we're in the middle of doing with it, and replace it with new stuff based on what we now believe to be in that branch or those branches."

(Is that really the right answer? What if we're in the middle of compiling or testing? Well, we claimed it was the right answer; onward.)

What we'll do here on B, then, is set up our --bare repository with a hookthis can be the post-update hook or the post-receive hookthat runs after some branch(es) is/are updated. Both "post" hooks are run just once per receive (basically once for each push), and given a list of all updates. The post-update hook gets all updated ref-names as arguments, while the post-receive hook gets all updated refs, including both old and new SHA-1s, on stdin.

(The complexity here is that in one push, I can update more than one branch and/or tag. For instance, with git push c0ffee3:master badf00d:refs/tags/new-tag, I can tell you to update your master branch to make it point to commit c0ffee3, and to create a tag pointing to object badf00d. Here, your post-update hook would get refs/heads/master refs/tags/new-tag, while your post-receive hook would be able to read two lines, roughly oldsha1 c0ffee3 refs/heads/master and then 0000000 badf00d refs/tags/new-tag, from stdin. These would all be full 40-character SHA-1s of course.)

Because we've decided that we'll just blow away the "bare work tree", all we have to do in this hook is find out if an interesting branch has been updated. Let's say we care specifically (and only) about a branch named develop, i.e., the ref-name refs/heads/develop. Then in a post-receive hook written as a shell script, our stdin scan loop might look like this:

do_update=false
while read oldsha newsha ref; do
    [ $ref = refs/heads/develop ] && do_update=true
done

In a post-update hook, we would just check arguments:

do_update=false
for ref do
    [ $ref = refs/heads/develop ] && do_update=true
done

Either way, if we see that the interesting branch has changed, we now want to do the blow-away-and-rebuild step:

blow_away_and_rebuild()
{
    local target_dir=$1 branch=$2

    rm -rf $target_dir
    mkdir $target_dir
    GIT_WORK_TREE=$target_dir git checkout -f $target_dir
}

if $do_update; then
    blow_away_and_rebuild /home/me/develop.dir develop
fi
exit 0 # succeed, regardless of actual success

Note that the git checkout step above populates the (removed and re-created) "bare work tree", but also has the side effect of setting the "current branch" (and fussing with git's index). This is how "current branch" manages to sneak in even though we have a nominally bare repository. We often don't need the rm -rf step, but if you have two different branches you'll "deploy" in this fashion, it sidesteps the "single current branch = single index" model git uses, which otherwise may leave old files behind.

The other trick here is that since /home/me/develop.dir has no .git directory within it (hence "bare work tree"), I won't be fooled into going into it, checking out a branch, and starting to edit there. Of course I can still be fooled into going into it and starting to work there, but at least I won't blame git if suddenly all my work gets rm -rf-ed. :-)

How can I push and automatically update working copy of my non-bare re...

git
Rectangle 27 9

[String].joined(separator: ",")
  • Those with side-effects should read as imperative verb phrases, e.g., print(x), x.sort(), x.append(y).
  • Name Mutating/nonmutating method pairs consistently. A mutating method will often have a nonmutating variant with similar semantics, but that returns a new value rather than updating an instance in-place. Swift: API Design Guidelines

Swift: how can String.join() work custom types? - Stack Overflow

swift
Rectangle 27 4

Hopefully the comments in the code example, be able to tell what you doing wrong in your code :-), otherwise there is always a reason to put forth your doubts...

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;

public class Game extends JPanel {
    /*
     * Now x and y are instance variables,
     * whose values you can change at each
     * MouseMove Event, and call repaint()
     * to see the effects
     */

    private int x;
    private int y;
    private MouseAdapter mouseActions =
        new MouseAdapter() {
        @Override
        public void mouseMoved(MouseEvent me) {
            /*
             * Now as the Mouse moves, we simply
             * updating the instance variables,
             * i.e. x and y to the new values
             * of the Mouse Location and calling
             * repaint() to draw the rectangle.
             * Since this class (Game) extends JPanel,
             * hence all the functions of the JPanel
             * belongs to this class, hence like
             * as we call any other method of this
             * class, without using the object,
             * we can call repaint, likewise.
             */
            x = me.getX();
            y = me.getY();
            repaint();
        }
    };

    /*
     * This JPanel panel is unnecessary in 
     * this case, since the class itself 
     * extends JPanel, hence you can use
     * this (keyword) to access the instance
     */
    //JPanel panel;
    // Not needed for this case.
    //JButton button2;
    //JButton button;
    public void game() {

        JFrame frame = new JFrame("Game");
        frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        frame.setResizable(false);
        addMouseMotionListener(mouseActions);
        /*
         * Here this means the instance
         * of the current class
         */
        frame.add(this);
        frame.pack();
        frame.setLocationByPlatform(true);
        frame.setVisible(true);
    }

    /*
     * While overriding methods of the 
     * super class, try to keep the 
     * ACCESS SPECIFIER, as close to
     * the original thingy as possible
     * In this case, it's protected
     * and not public
     */
    @Override
    protected void paintComponent(Graphics g) {

        /*
         * Do not perform calculation in this method
         * atleast.
         */
        super.paintComponent(g);
        g.fillRect(x, y, 100, 100);
    }

    public static void main(String[] args) {
        Runnable runnable = new Runnable() {
            @Override
            public void run() {
                new Game().game();
            }
        };
        EventQueue.invokeLater(runnable);
    }

    @Override
    public Dimension getPreferredSize() {
        return new Dimension(500, 500);
    }
}

+1 nice, if I had to nitpick, rather override getPreferredSize of JPanel and return the dimensions you want, and remove JFrame#setSize() and use pack() before setting JFrame visible :)

@DavidKroukamp : Please, if you may do those changes, I be too obliged. I am on my iPad, so formatting the code will be a bit tough for me. Suggestions are too good, else I have to wait till morning to do he edits :( For the rest THANKYOU and KEEP SMILING.:-)

@nIcEcOw: I took the liberty making the changes that David suggested.

getPreferredSize()
JPanel

Sign up for our newsletter and get our top new questions delivered to your inbox (see an example).

swing - Java - repainting JPanel gives an error - Stack Overflow

java swing jpanel repaint
Rectangle 27 4

Hopefully the comments in the code example, be able to tell what you doing wrong in your code :-), otherwise there is always a reason to put forth your doubts...

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;

public class Game extends JPanel {
    /*
     * Now x and y are instance variables,
     * whose values you can change at each
     * MouseMove Event, and call repaint()
     * to see the effects
     */

    private int x;
    private int y;
    private MouseAdapter mouseActions =
        new MouseAdapter() {
        @Override
        public void mouseMoved(MouseEvent me) {
            /*
             * Now as the Mouse moves, we simply
             * updating the instance variables,
             * i.e. x and y to the new values
             * of the Mouse Location and calling
             * repaint() to draw the rectangle.
             * Since this class (Game) extends JPanel,
             * hence all the functions of the JPanel
             * belongs to this class, hence like
             * as we call any other method of this
             * class, without using the object,
             * we can call repaint, likewise.
             */
            x = me.getX();
            y = me.getY();
            repaint();
        }
    };

    /*
     * This JPanel panel is unnecessary in 
     * this case, since the class itself 
     * extends JPanel, hence you can use
     * this (keyword) to access the instance
     */
    //JPanel panel;
    // Not needed for this case.
    //JButton button2;
    //JButton button;
    public void game() {

        JFrame frame = new JFrame("Game");
        frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        frame.setResizable(false);
        addMouseMotionListener(mouseActions);
        /*
         * Here this means the instance
         * of the current class
         */
        frame.add(this);
        frame.pack();
        frame.setLocationByPlatform(true);
        frame.setVisible(true);
    }

    /*
     * While overriding methods of the 
     * super class, try to keep the 
     * ACCESS SPECIFIER, as close to
     * the original thingy as possible
     * In this case, it's protected
     * and not public
     */
    @Override
    protected void paintComponent(Graphics g) {

        /*
         * Do not perform calculation in this method
         * atleast.
         */
        super.paintComponent(g);
        g.fillRect(x, y, 100, 100);
    }

    public static void main(String[] args) {
        Runnable runnable = new Runnable() {
            @Override
            public void run() {
                new Game().game();
            }
        };
        EventQueue.invokeLater(runnable);
    }

    @Override
    public Dimension getPreferredSize() {
        return new Dimension(500, 500);
    }
}

+1 nice, if I had to nitpick, rather override getPreferredSize of JPanel and return the dimensions you want, and remove JFrame#setSize() and use pack() before setting JFrame visible :)

@DavidKroukamp : Please, if you may do those changes, I be too obliged. I am on my iPad, so formatting the code will be a bit tough for me. Suggestions are too good, else I have to wait till morning to do he edits :( For the rest THANKYOU and KEEP SMILING.:-)

@nIcEcOw: I took the liberty making the changes that David suggested.

getPreferredSize()
JPanel

swing - Java - repainting JPanel gives an error - Stack Overflow

java swing jpanel repaint
Rectangle 27 8

UPDATE: I stepped through mvc source code (particularly DefaultModelBinder class) and here is what I found:

The class determines we are trying to bind a collection so it calls the method: UpdateCollection(...) which creates an inner ModelBindingContext that has a null Model property. Afterwards, that context is sent to the method BindComplexModel(...) which checks the Model property for null and creates a new instance of the model type if that is the case.

And so, only the values that are coming through the form/query string/route data are populated, the rest remains in its initialized state.

UpdateCollection(...)

Here is the method with my changes:

internal object UpdateCollection(ControllerContext controllerContext, ModelBindingContext bindingContext, Type elementType) {
IModelBinder elementBinder = Binders.GetBinder(elementType);

// build up a list of items from the request
List<object> modelList = new List<object>();
for (int currentIndex = 0; ; currentIndex++) {
    string subIndexKey = CreateSubIndexName(bindingContext.ModelName, currentIndex);
    if (!DictionaryHelpers.DoesAnyKeyHavePrefix(bindingContext.ValueProvider, subIndexKey)) {
        // we ran out of elements to pull
        break;
    }
    // **********************************************************
    // The DefaultModelBinder shouldn't always create a new
    // instance of elementType in the collection we are updating here.
    // If an instance already exists, then we should update it, not create a new one.
    // **********************************************************
    IList containerModel = bindingContext.Model as IList;
    object elementModel = null;
    if (containerModel != null && currentIndex < containerModel.Count)
    {
        elementModel = containerModel[currentIndex];
    }
     //*****************************************************
    ModelBindingContext innerContext = new ModelBindingContext() {
        Model = elementModel, // assign the Model property
        ModelName = subIndexKey,
        ModelState = bindingContext.ModelState,
        ModelType = elementType,
        PropertyFilter = bindingContext.PropertyFilter,
        ValueProvider = bindingContext.ValueProvider
    };
    object thisElement = elementBinder.BindModel(controllerContext, innerContext);

    // we need to merge model errors up
    VerifyValueUsability(controllerContext, bindingContext.ModelState, subIndexKey, elementType, thisElement);
    modelList.Add(thisElement);
}

// if there weren't any elements at all in the request, just return
if (modelList.Count == 0) {
    return null;
}

// replace the original collection
object collection = bindingContext.Model;
CollectionHelpers.ReplaceCollection(elementType, collection, modelList);
return collection;

asp.net mvc - Calling UpdateModel with a collection of complex data ty...

asp.net-mvc model-binding updatemodel
Rectangle 27 8

UPDATE: I stepped through mvc source code (particularly DefaultModelBinder class) and here is what I found:

The class determines we are trying to bind a collection so it calls the method: UpdateCollection(...) which creates an inner ModelBindingContext that has a null Model property. Afterwards, that context is sent to the method BindComplexModel(...) which checks the Model property for null and creates a new instance of the model type if that is the case.

And so, only the values that are coming through the form/query string/route data are populated, the rest remains in its initialized state.

UpdateCollection(...)

Here is the method with my changes:

internal object UpdateCollection(ControllerContext controllerContext, ModelBindingContext bindingContext, Type elementType) {
IModelBinder elementBinder = Binders.GetBinder(elementType);

// build up a list of items from the request
List<object> modelList = new List<object>();
for (int currentIndex = 0; ; currentIndex++) {
    string subIndexKey = CreateSubIndexName(bindingContext.ModelName, currentIndex);
    if (!DictionaryHelpers.DoesAnyKeyHavePrefix(bindingContext.ValueProvider, subIndexKey)) {
        // we ran out of elements to pull
        break;
    }
    // **********************************************************
    // The DefaultModelBinder shouldn't always create a new
    // instance of elementType in the collection we are updating here.
    // If an instance already exists, then we should update it, not create a new one.
    // **********************************************************
    IList containerModel = bindingContext.Model as IList;
    object elementModel = null;
    if (containerModel != null && currentIndex < containerModel.Count)
    {
        elementModel = containerModel[currentIndex];
    }
     //*****************************************************
    ModelBindingContext innerContext = new ModelBindingContext() {
        Model = elementModel, // assign the Model property
        ModelName = subIndexKey,
        ModelState = bindingContext.ModelState,
        ModelType = elementType,
        PropertyFilter = bindingContext.PropertyFilter,
        ValueProvider = bindingContext.ValueProvider
    };
    object thisElement = elementBinder.BindModel(controllerContext, innerContext);

    // we need to merge model errors up
    VerifyValueUsability(controllerContext, bindingContext.ModelState, subIndexKey, elementType, thisElement);
    modelList.Add(thisElement);
}

// if there weren't any elements at all in the request, just return
if (modelList.Count == 0) {
    return null;
}

// replace the original collection
object collection = bindingContext.Model;
CollectionHelpers.ReplaceCollection(elementType, collection, modelList);
return collection;

asp.net mvc - Calling UpdateModel with a collection of complex data ty...

asp.net-mvc model-binding updatemodel
Rectangle 27 22

Chance are that you have two instances of the JLabel. One is a class variable and one is an instance variable which has been added to the GUI. The problem is your code is updating the class variable.

Or, maybe if you don't update the icon on the EDT you might have problems.

Edit: Just reread the question. If you are talking about a "generated image" that needs to be reloaded from a file, then you need to get rid of the cached image. Two ways to do this:

//  Using ImageIO

String imageName = "timeLabel.jpg";
imageLabel.setIcon( new ImageIcon(ImageIO.read( new File(imageName) ) ) );

//  Or you can flush the image

String imageName = "timeLabel.jpg";
ImageIcon icon = new ImageIcon(imageName);
icon.getImage().flush();
imageLabel.setIcon( icon );

what if i want to update the image from database with blob type

java - How to change icon of a JLabel? - Stack Overflow

java swing
Rectangle 27 4

The issue that you are having is that you are always dealing with a single instance of a Person. So, you are adding, updating, and removing the same instance.

A better approach might be to use something like a personForEditing observable that contains a new person. Then, when doing addPerson you would add this person to the observableArray and replace personForEditing with a new instance for the next entry. Based on your code something like:

my.vm = function () {
    var people = ko.observableArray([]),
        addPerson = function (jh) {
            people.push(jh);
            personForEditing(new Person());
        },
        removePerson = function (jh) {
            people.remove(jh);
        },
        personForEditing = ko.observable(new Person())
    return {
        people: people,
        addPerson: addPerson,
        removePerson: removePerson,
        personForEditing: personForEditing
    };
}();

Perfect! Thanks RP Niemeyer. Answer from a knockout expert works like a charm :)

knockout.js - knockout add javascript object to an observable array - ...

knockout.js observable
Rectangle 27 5

You need the __block qualifier when updating a local variable. If you're updating a class property (or, in your case, an instance variable), the __block qualifier is not needed.

With an asynchronous block, updating local variables doesn't generally make sense, so you won't often see it in this context.

objective c - Is it necessary to use __block when setting a BOOL flag ...

objective-c block objective-c-blocks
Rectangle 27 13

Figured it out. The problem was that there's two of us working on this project, and my colleague created his own instance of DBContext he was updating one and i the other. So for who ever has this problem in the future make sure you don't have two different instances of your DBContext at the same time

c# - Store update, insert, or delete statement affected an unexpected ...

c# asp.net asp.net-mvc entity-framework
Rectangle 27 13

Figured it out. The problem was that there's two of us working on this project, and my colleague created his own instance of DBContext he was updating one and i the other. So for who ever has this problem in the future make sure you don't have two different instances of your DBContext at the same time

c# - Store update, insert, or delete statement affected an unexpected ...

c# asp.net asp.net-mvc entity-framework
Rectangle 27 16

If you're doing your processing on the UI thread, it won't be able to do anything else (like redraw updated labels) while the processing is running. So for instance, if the processing is happening because the user clicked a button and is triggered by the button click handler (without explicitly placing it on another thread), it's running on the UI thread. Even though you update the label's text, it doesn't get drawn until it receives a paint message, at which point it's probably busy doing your processing.

The answer is to do long-running processing on a separate thread. The hack (IMHO) is to use Application.DoEvents to let the UI thread do some UI stuff during your processing. If you put one of those after updating the label and before you start your processing, odds are pretty high the label will get repainted. But then, during the processing, no further paint events can get processed (leading to half-drawn windows when someone moves another app window over your app and back, etc.). Hence my calling it a hack (even though, er, um, I've been known to do it :-) ).

So I guess the "processing" is taking place on the UI thread but eventhandler is invoked on it's own thread...

I'm assuming DoSomeProcess is triggered from the UI thread (e.g., in direct response to a button click or similar). If so, then yes, your processing is definitely on the UI thread. Because TriggerProcessStarted triggers your callback asynchronously via BeginInvoke, you have no idea when it will run, but in any case your code then immediately launches into processing, never yielding, so no one else is going to be able to grab that thread. Since that's the UI thread, the call to the delegate will block on the Invoke call setting the label's text, whereupon it has to wait for the UI thread (which is busy processing). (And that's assuming it's scheduled on a different thread; I couldn't 100% convince myself either way, because Microsoft has two different BeginInvokes -- which IIRC one of the designers has acknowledged was a Really Dumb Idea -- and it's been a while since I fought with this stuff.)

If you make the TriggerProcessStarted calls to your callbacks synchronous, you should be okay. But ideally, schedule the processing (if it's not doing UI) on its own thread instead.

AFTER EDIT: You are right. I left BeginInvoke alone but changed my button click event to start DoSomeWork on it's own thread. That fixed it!

c# - Why won't control update/refresh mid-process - Stack Overflow

c# .net controls refresh
Rectangle 27 11

If the field is private and access is through getters and setters, you will be able to reimplement getters and setters (for instance, dropping the field and updating/reading the value from an external source), and thus change how the "field" works without touching any child classes.

This is argument #2, the "less compelling" stated in the question

Well, besides some minor package visibility details mentioned in other answers, I believe it's the only argument for making a field private with protected getters and setters. Personally, I don't think it's very compelling either... Getters and setters in Java are annoying.

java - protected data in abstract class - Stack Overflow

java abstract protected
Rectangle 27 25

You need a static property in your class, BUT, you need to assign it to an instance variable within the class if you want each object to contain the id it was created with.

Also, you'll want to use Interlocked.Increment on the counter in case you are updating multiple instances simultaneously:

public class Foo
    {
        private static int m_Counter = 0;

        public int Id { get; set; }

        public Foo()
        {
            this.Id = System.Threading.Interlocked.Increment(ref m_Counter);
        }
    }

+1 - exactly as I pointed out in @Browman98's answer.

volatile
Interlocked.Increment

@DannyChen: It may be simpler, but it's not safer. See this discussion for more details: stackoverflow.com/questions/154551/

@competent_tech: It seems that I misunderstood this keyword for a few years...oh GOD!

@Klitos Interlocked.Increment returns the incremented value so no race condition here, nothing is copying the m_Counter field directly to instanceA.Id or instanceB.Id

c# - Incrementing a unique ID number in the constructor - Stack Overfl...

c# constructor auto-increment
Rectangle 27 2

You cannot do precisely what you ask -- you can't associate both a static string and a variable to a label at the same time. There are things you can do to get the desired effect, but all you're doing is adding complexity with no real gain. For example, you can assign an instance of StringVar to the textvariable attribute of the Label widget. When you do that, any update to the variable will update the label. However, you end up having to make a function call to update the variable, so you don't really gain anything over making a function call to update the label directly.

Another option is to use two labels -- one for the static text and one for the variable. Put them side-by side with no border so the user won't notice. Then, when you update the variable you'll get the desired effect. However, you're still having to make a function call to set the variable so you don't really gain much.

Yet another option is to use two instances of StringVar -- one for the label, and another for the name. You can put a trace on the name variable so that when it changes, you automatically update the other variable with the static string and the value of the name variable, and that will cause the label to be automatically updated. Again, however, you're having to make a function call to put everything in motion

So, as you can see, there are options, but they all add complexity to your code with no real gain over simply updating the label directly. The only time these other methods gain you an advantage is when the value needs to appear in more than one widget at once. In that case you can associate the variable with two or more widgets, and a single function call will update all associated widgets.

Yes -- standard Tkinter .... does that. Appreciate you say the same. Your notice on a cost of growing complexity, that is needed to solve the Customer Task is fair. The rest just finds the way, how to make the Customer Task done and finally, after 15 hours say, Yes -- it is possible. It works.

Update Label Text in Python TkInter - Stack Overflow

python tkinter
Rectangle 27 3

The only real advantage I can think of, would be that XSLT renderings are easier to deploy in isolation. Say, for instance, that you're updating your "News Spots" rendering and you want to deploy this change to test/production right away - it would be a simple case of uploading the .xsl file itself.

Using .NET development (and enduring the Web Application Project model), a deployment of the code base would implicitly deploy any and all changes to the affected assemblies - including whatever work you have in progress.

There are, of course, ways you can manage this. Source code branching/merging and so on - but that's an additional layer of complexity to your solution.

xslt - What are the advantages of using XSL in Sitecore instead of C#?...

xslt sitecore sitecore6
Rectangle 27 2

  • Make sure the timer the instance of NSTimer is not released meanwhile.
removeOverlay
  • Put a breakpoint in the removeLayout method to see if it fires.
timerWithTimeInterval
scheduledTimerWithTimeInterval

To perform code on main thread (allows UI updating):

- (void)removeOverlay {
  dispatch_async(dispatch_get_main_queue(), ^{
     // update ui
  });
}

it does do UI, however I know that it is not called because of an NSLog

neither a breakpoint nor an NSLog are fired

I improved the answer. "You are not scheduling the timer. Replace the timerWithTimeInterval with scheduledTimerWithTimeInterval"

Sign up for our newsletter and get our top new questions delivered to your inbox (see an example).

iphone - NSTimer not operating as expected - Stack Overflow

iphone objective-c ios nstimer
Rectangle 27 6

You have to create a new instance at every insert, like this, otherwise you are just updating one model over and over.

$queryResults = $command->queryAll();

foreach ($queryResults as $CActive) {
    $model=new Campaigns;  
    $model->attributes=$CActive;

    if($model->save($CActive))  echo "Good!";
}

Thanks!! that is what i thought... isnt this very resource consuming?

The instance creation isn't, but the inserts will definitely take their toll.

php - Creating or updating multiple mysql lines using Yii model - Stac...

php mysql frameworks yii
Rectangle 27 3

I can't think of a way to make IB update all "instances" at design time when a single instance has a property value change (And I think this would generally be undesired and non-standard behavior). I'm fairly certain it can't be done because I don't think IB keeps an instance of your custom view in memory for the duration of the IB session. I think what it does is instantiate the view, set properties on it, snapshot it for rendering, then releases it.

It should be possible to set up properties that set "default" values to be used by future instances of your view. We can achieve this by storing "default" values in NSUserDefaults (XCode's), and reading the default value inside initWithFrame:, which IB will call to initialize a new instance. We can gate all this default stuff using #if TARGET_INTERFACE_BUILDER so it doesn't show up at runtime on the device.

IB_DESIGNABLE
@interface CoolView : UIView

@property (strong, nonatomic) IBInspectable UIColor* frameColor;

#if TARGET_INTERFACE_BUILDER
@property (strong, nonatomic) IBInspectable UIColor* defaultFrameColor;
#endif

@end

@implementation CoolView

- (id) initWithFrame:(CGRect)frame
{
    self = [super initWithFrame: frame];
    if ( self != nil ) {

#if TARGET_INTERFACE_BUILDER
        NSData *colorData = [[NSUserDefaults standardUserDefaults] objectForKey: @"defaultCoolViewFrameColor"];
        if ( colorData != nil ) {
            self.frameColor = [NSKeyedUnarchiver unarchiveObjectWithData: colorData];;
        }
#endif

    }
    return self;
}

- (void) drawRect:(CGRect)rect
{
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetLineWidth(context, 10);
    CGRect f = CGRectInset(self.bounds, 10, 10);
    [self.frameColor set];
    UIRectFrame(f);
}

#if TARGET_INTERFACE_BUILDER
- (void) setDefaultFrameColor:(UIColor *)defaultFrameColor
{
    _defaultFrameColor = defaultFrameColor;

    NSData *colorData = [NSKeyedArchiver archivedDataWithRootObject: defaultFrameColor];
    [[NSUserDefaults standardUserDefaults] setObject:colorData forKey:@"defaultCoolViewFrameColor"];
}
#endif

@end

You could probably get closer to your original goal (updating all "instances" in IB) if you're okay with forcing IB to reload your xib/storyboard file altogether. To do this you'd likely have to use the technique above and extend it to include code in a custom initWithCoder: method on your view.

Possibly possibly you could get really tricky and try to "touch" the xib file that is being edited, and that might prompt IB to reload?

Sophisticated. Will have to investigate this!

"I can't think of a way to make IB update all "instances" at design time"... it's a good point. So, when you have ab IBDesignable, and you change the code (even trivially), it does indeed "re-storyboard-compile" the whole storyboard. So I think really, the only way to achieve what I'm saying is, indeed you have to have a value in a code file, and change that. (That's still highly convenient, much better than buggering around changing 100 IBInspectables or constraints.)

ios - Some sort of "global" for IBDesignables? - Stack Overflow

ios uistoryboard nslayoutconstraint ibinspectable